1

我需要制作一个没有任何链接但在属性中带有 url 的菜单。
url 应该在 data-href="|" 但现在只有标题会打印在属性中。
有没有办法只返回 url 而不是链接。IE。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
}
4

2 回答 2

3

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

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
}
于 2013-06-14T09:57:12.850 回答
1

仅当您没有任何挂载点时,上述答案才有效。一旦在页面树中有挂载点,这些链接将不会正确生成。

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

我编写了一个可以通过 IProcFunc 调用的小方法,它将删除 a-Tag 并将页面标题替换为链接的 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

这应该可以解决问题。

于 2013-12-03T14:06:48.920 回答