将菜单链接URL放在属性中

时间:2013-06-14 09:40:03

标签: typo3 typoscript

我需要创建一个没有任何链接的菜单,但需要在属性中添加url 网址应该是data-href =“|”但现在只有标题会打印在属性中 有没有办法只返回网址而不是链接。即。 http://example.com代替Example

或者有人知道不同的解决方案吗?

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
}

2 个答案:

答案 0 :(得分:2)

试试这个(未经测试的代码):

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
}

答案 1 :(得分:1)

只要您没有任何挂载点,上述答案才有效。只要在页面树中有挂载点,就不会正确生成这些链接。

即使在使用挂载点时,要强制HMENU输出没有周围的a-Tag和页面标题的纯URL,您需要定义HMENU的IProcFunc属性。

我写了一个小方法,可以通过IProcFunc调用,它将删除a-Tags并用链接的URL替换页面标题。

<?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;
    }
}

?>

只需将此小类保存在某处(例如/fileadmin/libs/class.userFuncUtils.php)并将其包含在

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

然后将HMENU的IProcFunc属性设置为指向此用户函数

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

这应该可以解决问题。