TYPO3 menu - duplicate parent link on submenu list

我的梦境 提交于 2019-12-13 00:49:09

问题


Is it possible to insert the parent link to sub menu list. It should looks like this:

Parent link
|--Parent link
|--Subpage link1
|--Subpage link

I need this for bootstrap menu where every parent link is only clickable (to expand the sub menu)

My menu looks like this:

lib.header-menu = HMENU
lib.header-menu.entryLevel = 0
lib.header-menu {
    1 = TMENU
    1 {                                                                                                                                                                                                                                                                                                                                                               
        wrap = <nav class="navbar navbar-default" role="navigation"><ul class="nav navbar-nav">|</ul></nav>  
        expAll = 1
        NO {
            ATagTitle.field = title
            wrapItemAndSub = <li>|</li>
            stdWrap.htmlSpecialChars = 1
            accessKey = 1
        }
        IFSUB < .NO
        IFSUB = 1
        IFSUB {
            wrapItemAndSub = <li class="dropdown">|</li>
            linkWrap= |<span class="caret"></span>
            ATagParams = class="dropdown-toggle" role="button" data-toggle="dropdown"
            ATagBeforeWrap = 1
            stdWrap.htmlSpecialChars = 1
        }
        ACTIFSUB < .IFSUB
        ACTIFSUB {
            wrapItemAndSub = <li class="active dropdown">|</li>
        }
        ACT < .NO
        ACT = 1
        ACT {
            wrapItemAndSub = <li class="active">|</li>
        }
        CURIFSUB < .IFSUB
        CURIFSUB = 1
        CURIFSUB {
            wrapItemAndSub = <li class="active dropdown">|</li>
        }
    }
    # second level
    2 = TMENU
    2.wrap = <ul class="dropdown-menu">|</ul>
    2{
        expAll = 1
        NO{
            ATagTitle.field = title
            wrapItemAndSub = <li>|</li>
        }
        IFSUB = 1
        IFSUB{
            ATagTitle.field = title
            wrapItemAndSub = <li>|</li>
        }
    }
}

回答1:


One solution is to include an additional subpage with a shortcut to the parent page. This requires manual labour though and can be forgotten.

You could also use typoscript to get it done. I've changed the wrapper on the 2nd item so it's build up as COA with several parts, and created a typolink to field:pid (its parent). By leaving the text value empty, typolink will create a link with the title of the page being linked to. Solving the problem of retrieving the title of the parent page on the go.

lib.header-menu-nieuw = HMENU
lib.header-menu-nieuw.entryLevel = 0
lib.header-menu-nieuw {
    1 = TMENU
    1 {                                                                                                                                                                  
        wrap = <nav class="navbar navbar-default" role="navigation"><ul class="nav navbar-nav">|</ul></nav>  
        expAll = 1
        NO {
            ATagTitle.field = title
            wrapItemAndSub = <li>|</li>
            stdWrap.htmlSpecialChars = 1
            accessKey = 1
        }
        IFSUB < .NO
        IFSUB = 1
        IFSUB {
            wrapItemAndSub = <li class="dropdown">|</li>
            linkWrap= |<span class="caret"></span>
            ATagParams = class="dropdown-toggle" role="button" data-toggle="dropdown"
            ATagBeforeWrap = 1
            stdWrap.htmlSpecialChars = 1
        }
        ACTIFSUB < .IFSUB
        ACTIFSUB {
            wrapItemAndSub = <li class="active dropdown">|</li>
        }
        ACT < .NO
        ACT = 1
        ACT {
            wrapItemAndSub = <li class="active">|</li>
        }
        CURIFSUB < .IFSUB
        CURIFSUB = 1
        CURIFSUB {
            wrapItemAndSub = <li class="active dropdown">|</li>
        }
    }
    # second level
    2 = TMENU
    2.stdWrap.wrap.stdWrap.cObject = COA
    2.stdWrap.wrap.stdWrap.cObject {
        10 = TEXT
        10.typolink.parameter = {field:pid}
        10.typolink.parameter.insertData = 1
        10.wrap = <ul class="dropdown-menu"><li>|</li>
        20 = TEXT
        20.value = |</ul>
    }
    2{
        expAll = 1
        NO{
            ATagTitle.field = title
            wrapItemAndSub = <li>|</li>
        }
        IFSUB = 1
        IFSUB{
            ATagTitle.field = title
            wrapItemAndSub = <li>|</li>
        }
    }
}

This creates a block where each parent page automatically is the first subpage item as well.



来源:https://stackoverflow.com/questions/34089412/typo3-menu-duplicate-parent-link-on-submenu-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!