Patrik
Patrik

Reputation: 2247

Put the menu link url in an attribute

I need to make a menu without any links but with the url in an attribute.
The url should be in data-href="|" but now only the title will be printed in the attribute.
Is there a way to only return the url and not the link. ie. http://example.com instead of Example

Or does anyone know a different solution?

lib.mainMenu = HMENU
lib.mainMenu {
    entryLevel = 1
    wrap = <ul id="dropDownMenu">|</ul>

    1 = TMENU
    1 {
        noBlur = 1
        expAll = 1

        NO = 1
        NO {
            wrapItemAndSub = <li class="nochildren">|</li>
            stdWrap2.wrap = <span>|</span>
        }

        ACT < .NO
        ACT.wrapItemAndSub = <li class="active nochildren">|</li>

        # if has children
        IFSUB < .NO
        IFSUB.wrapItemAndSub = <li class="haschildren">|</li>
        IFSUB.allWrap = |

        # if has children and is active
        ACTIFSUB < .IFSUB
        ACTIFSUB.wrapItemAndSub = <li class="active haschildren">|</li>
        ACTIFSUB.allWrap = |
    }

    2 < .1    
    2 {
        wrap = <ul id="subMenu">|</ul>
        NO.ATagParams = rel="nofollow"
        NO.stdWrap2.insertData = 1
        NO.stdWrap2.wrap = <span data-href="|" class="link">{field:title}</span>
        NO.doNotLinkIt = 1

        IFSUB < .NO
        ACTIFSUB < .IFSUB
    }

    3 < .2
}

Upvotes: 1

Views: 3851

Answers (2)

dachande
dachande

Reputation: 11

The above answer only works as long as you don't have any mountpoints. As soon as you have mountpoints in your page tree, these links will not be generated correctly.

To force a HMENU to output plain URLs without a surrounding a-Tag and page title even when using mountpoints, you need to define the IProcFunc property of HMENU.

I've written a small method which can be called through IProcFunc which will remove the a-Tags and replace the page title with the URL of the link.

<?php

class UserFuncUtils {

    /**
     * Modifies sitemap links. Whith this modification, a menu will only generate a plain url instead of an <a>-Tag
     *
     * This is an IProcFunc for a HMENU. The only parameter supplied by this method call is $this->I from the
     * Menu ContentObject. The function call expects a modified $I array to be returned.
     */
    function IProcFunc_plainURL($I) {
        // Show what $I has to offer
        // print \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($I, NULL, 8, FALSE, FALSE, FALSE, array(), array());

        // Remove opening and closing tags and replace title with href attribute. This results in a plain URL being rendered by the menu
        $I['parts']['ATag_begin'] = '';
        $I['parts']['ATag_end'] = '';
        $I['parts']['title'] = $I['linkHREF']['HREF'];

        return $I;
    }
}

?>

Just save this small class somewhere (e.g. /fileadmin/libs/class.userFuncUtils.php) and include it with

includeLibs.userFuncUtils = fileadmin/libs/class.userFuncUtils.php

and then set the IProcFunc property of HMENU to point to this user function

lib.mainMenu = HMENU
lib.mainMenu.IProcFunc = UserFuncUtils->IProcFunc_plainURL

This should do the trick.

Upvotes: 1

tmt
tmt

Reputation: 8614

Try this (untested code):

lib.mainMenu = HMENU
lib.mainMenu {
    entryLevel = 1
    wrap = <ul id="dropDownMenu">|</ul>

    1 = TMENU
    1 {
        noBlur = 1
        expAll = 1

        NO = 1
        NO {
            wrapItemAndSub = <li class="nochildren">|</li>
            stdWrap2.wrap = <span>|</span>
        }

        ACT < .NO
        ACT.wrapItemAndSub = <li class="active nochildren">|</li>

        # if has children
        IFSUB < .NO
        IFSUB.wrapItemAndSub = <li class="haschildren">|</li>
        IFSUB.allWrap = |

        # if has children and is active
        ACTIFSUB < .IFSUB
        ACTIFSUB.wrapItemAndSub = <li class="active haschildren">|</li>
        ACTIFSUB.allWrap = |
    }

    2 < .1    
    2 {
        wrap = <ul id="subMenu">|</ul>
        NO {
            doNotShowLink = 1
            stdWrap2 {
                wrap >
                cObject = TEXT
                cObject {
                    typolink {
                        parameter.field = uid
                        returnLast = url
                    }
                    insertData = 1
                    wrap = <span data-href="|" class="link">{field:nav_title//field:title}</span>
                }
            }
        }

        IFSUB < .NO
        ACTIFSUB < .IFSUB
    }

    3 < .2
}

Upvotes: 3

Related Questions