Typoscript navigation with subpages

笑着哭i 提交于 2019-12-01 21:14:09

The option noBlur is removed since TYPO3 v6.0 and I read somewhere, that the RO state does something with javascript to show/hide the submenu - so I try not to use it. I rather do the showing/hiding via css.

I would've done it like this:

lib.menu = HMENU
lib.menu {
    special = list
    special.value = 3,2

    1 = TMENU
    1 {
        expAll = 1
        wrap = <ul class="nav">|</ul>

        NO.wrapItemAndSub = <li>|</li>

        CUR = 1
        CUR.wrapItemAndSub = <li class="active">|</li>

        ACT < .CUR
    }

    2 = TMENU
    2 {
        wrap = <ul>|</ul>

        NO = 1
        NO.wrapItemAndSub = <li>|</li>
    }
}

Add the hover-effect via CSS:

.nav ul {
    display: none;
}
.nav li:hover ul {
    display: block;
}

The <ul> wrap of your subnavi should be around the TMENU. I don't think you need the ATagBeforeWrap as it only makes linkWrap within the <a> tag. So it should look like this (not tested):

lib.menu = HMENU
lib.menu {
  special = list
  special.value = 3,2

  1 = TMENU
  1 {
    wrap = <ul class="nav">|</ul>
    expAll = 1
    NO.wrapItemAndSub = <li class="">|</li>
    RO < .NO
    RO = 1
    CUR < .NO
    CUR = 1
    CUR.wrapItemAndSub = <li class="active">|</li>
    ACT < .CUR

    noBlur = 1
    IFSUB = 1
    IFSUB.wrapItemAndSub= <li class="dropdown">|</li>
  }

  2 = TMENU
  2 {
    wrap = <ul class="dropdown-menu">|</ul>
    expAll = 1
    noBlur = 1
    NO = 1
    NO.wrapItemAndSub = <li>|</li>
  }
}

Here you can find good info about wraps, unfortunately it's in german: http://jweiland.net/typo3/typoscript/wrap-moeglichkeiten-und-hierarchie-in-menues.html

By the way: if you are using TYPO3 6+ the noBlur setting has been removed.

---> EDIT:

I shortened your code a little, but I really coudn't reproduce the problem. For me it's working fine. The li around the dropdown gets the dropdown class. But I don't see a duplicate of the <ul class="dropdown-menu">

  special = list
  special.value = 3,2

  1 = TMENU
  1 {
    wrap = <ul class="nav">|</ul>
    expAll = 1
    NO = 1
    NO.wrapItemAndSub = <li class="">|</li>
    RO < .NO
    CUR < .NO
    CUR.wrapItemAndSub = <li class="active">|</li>
    ACT < .CUR

    IFSUB = 1
    IFSUB.wrapItemAndSub= <li class="dropdown">|</li>
    IFSUB.ATagParams = class="dropdown-toggle" data-toggle="dropdown"
    IFSUB.stdWrap.innerWrap= |<b class="caret"></b>

    ACTIFSUB < .IFSUB
    CURIFSUB < .IFSUB
  }

  2 = TMENU
  2 {
    wrap = <ul class="dropdown-menu">|</ul>
    expAll = 1
    NO = 1
    NO.wrapItemAndSub = <li>|</li>
  }

This snippet I have used for internal page links:

I have used subtitle field for internal navigation.

for example:

<a href="#about>about</a>
<a href="#ourservice">Ourservice</a>
menu.main_menu = HMENU
menu.main_menu {

#special = directory
#special.value = 2

    1 = TMENU
    1 {
         wrap = <ul class="nav navbar-nav navbar-right">|</ul>
         expAll = 1
         noBlur = 1

         NO = 1
         NO {
            doNotLinkIt = 1
            allWrap.insertData = 1
           allWrap = <li class="first menu-{field:uid}"><a href="#{field:subtitle}">|</a></li>                      
          }

          ACT < .NO
          ACT {
               ATagParams = class="active dropdown"
               allWrap = <li class="active first menu-{field:uid}">|</li> |*| <li class="active menu-{field:uid}">|</li>
         }

         CUR < .NO
         CUR {
             ATagParams = class="parent_menu active"
             allWrap = <li class="first active menu-{field:uid}">|</li> |*| <li class="active menu-{field:uid}">|</li>
        }
    }   
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!