TYPO3 menu - duplicate parent link on submenu list

2019-08-06 19:02发布

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条回答
萌系小妹纸
2楼-- · 2019-08-06 19:55

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.

查看更多
登录 后发表回答