简体   繁体   English

TYPO3带有引导程序的第三个导航级别

[英]TYPO3 third navigation level with bootstrap

I have the following typoscript snippet which makes me a drop down navigation with bootstrap. 我有以下印刷文字片段,这使我可以使用引导程序进行下拉导航。

 MENU = HMENU
    MENU.entryLevel = 0
    #NAVIMAIN.excludeUidList = 

    MENU {
    1 = TMENU
    1 {
      expAll = 1

    NO.allWrap = <li>|</li>
    NO.ATagTitle.field = abstract // description // title

    ACT = 1
    ACT.wrapItemAndSub = <li class="active">|</li>
    ACT.ATagTitle.field = abstract // description // title

    IFSUB = 1
    IFSUB.before = <a href="#" class="dropdown-toggle" data-toggle="dropdown">
    IFSUB.after =  <b class="caret"></b></a>
    IFSUB.doNotLinkIt = 1
    IFSUB.wrapItemAndSub = <li class="dropdown">|</li>
    IFSUB.ATagTitle.field = abstract // description // title

    ACTIFSUB = 1
    ACTIFSUB.before = <a href="#" class="dropdown-toggle" data-toggle="dropdown">
    ACTIFSUB.after =  <b class="caret"></b></a>
    ACTIFSUB.doNotLinkIt = 1
    ACTIFSUB.wrapItemAndSub = <li class="dropdown active">|</li>
    ACTIFSUB.ATagTitle.field = abstract // description // title

    wrap = <ul class="nav navbar-nav">|</ul>
  }

       2 = TMENU
  2 {
    expAll = 1

    ACT = 1
    ACT.wrapItemAndSub = <li class="active">|</li>
    ACT.ATagTitle.field = abstract // description // title

    ACTIFSUB = 1
    ACTIFSUB.wrapItemAndSub = |
    ACTIFSUB.before = <li class="divider"></li><li class="nav-header">
    ACTIFSUB.after = </li>
    ACTIFSUB.doNotLinkIt = 1
    ACTIFSUB.ATagTitle.field = abstract // description // title

    NO.allWrap = <li>|</li>
    NO.ATagTitle.field = abstract // description // title

    IFSUB = 1
    IFSUB.before = <li class="divider"></li><li class="nav-header">
    IFSUB.after = </li>
    IFSUB.doNotLinkIt = 1
    IFSUB.ATagTitle.field = abstract // description // title

    SPC = 1
    SPC.allWrap = <li class="divider"></li><li class="nav-header">|</li>

    wrap = <ul class="dropdown-menu">|</ul>
  }

How can I add a third level Menü as dropdown of a second level menü? 如何添加第三级菜单作为第二级菜单的下拉菜单?

Thanks in advance. 提前致谢。

The default navbar of Bootstrap only supports two levels. Bootstrap的默认导航栏仅支持两个级别。 I'd recommend using Smartmenus jQuery to get three or more sublevels. 我建议使用Smartmenus jQuery获得三个或更多子级别。

The adapted HMENU setup for TYPO3 would be like this: 为TYPO3改编的HMENU设置如下:

lib.bootstrap3-smartmenus = COA
lib.bootstrap3-smartmenus {
  wrap = <nav class="navbar navbar-default" role="navigation"> <div class="container-fluid"> | </div> </nav>
  
  10 = COA
  10 {
    wrap = <div class="navbar-header"> | </div>
    10 = COA
    10 {
      // hamburger icon:
      wrap = <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | </button>
      10 = TEXT
      10.value = <span class="sr-only">Toggle navigation</span>
      20 = TEXT
      20.value = <span class="icon-bar"></span>
      21 < .20
      22 < .20
    }
  
    // company name/logo:
    20 = TEXT
    20.value = Project name
    20.typolink {
      parameter = http://www.example.org/
      ATagParams = class="navbar-brand"
    }
  }
  
  20 = COA
  20 {
    wrap = <div class="navbar-collapse collapse"> | </div>
  
    10 = HMENU
    10 {
      wrap = <ul class="nav navbar-nav"> | </ul>
  
      1 = TMENU
      1 {
        expAll = 1
  
        NO = 1
        NO {
          ATagTitle.field = title
          wrapItemAndSub = <li>|</li>
        }
  
        CUR < .NO
        CUR {
          wrapItemAndSub = <li class="active">|</li>
        }
 
        IFSUB = 1
        IFSUB {
          ATagTitle.field = title
          ATagParams = class="sub-arrow"
          linkWrap = |<span class="caret"></span>
          ATagBeforeWrap = 1
          wrapItemAndSub = <li>|</li>
        }
 
        CURIFSUB < .IFSUB
        CURIFSUB {
          wrapItemAndSub = <li class="active">|</li>
        }
  
        ACT < .CUR
        ACTIFSUB < .CURIFSUB
  
        SPC = 1
        SPC {
          // no divider, if first menu item on this level (using optionSplit):
          wrapItemAndSub = <li class="dropdown-header">|</li> |*| <li class="divider"></li><li class="dropdown-header">|</li>
        }
      }
  
      2 < .1
      2 {
        wrap = <ul class="dropdown-menu">|</ul>
  
      }
  
      3 < .2
      4 < .3
    }
  }
}

Some changes to the markup must be made (eg no more data-toggle="dropdown" ). 必须对标记进行一些更改(例如,不再进行data-toggle="dropdown" )。

In addition to the default Bootstrap files, these CSS and JavaScripts must be used: 除了默认的Bootstrap文件之外,还必须使用以下CSS和JavaScript:

  • jquery.smartmenus.bootstrap.css jquery.smartmenus.bootstrap.css
  • jquery.smartmenus.min.js jquery.smartmenus.min.js
  • jquery.smartmenus.bootstrap.min.js jquery.smartmenus.bootstrap.min.js

I once created a demo (including this information) here . 我曾经在这里创建一个演示(包括此信息)。


Edit: If you rather want to extend the default Bootstrap navbar with the provided example, you can use the following TypoScript setup. 编辑:如果您想通过提供的示例扩展默认的Bootstrap导航栏,则可以使用以下TypoScript设置。 I successfully tested it with the extra CSS of the Codepen example. 我使用Codepen示例的额外CSS成功地对其进行了测试。

It removes the caret element in sublevels and add the extra classes you need. 它将删除子级别中的插入符号元素,并添加所需的其他类。 You can adjust the classes container / container-fluid and navbar-fixed-top to your needs. 您可以根据需要调整类container / container-fluidnavbar-fixed-top

This TypoScript (as well as the snippet above) will also take care of menu separator pages in TYPO3 ( SPC ) and adds the divider element of Bootstrap only, if it is not the first subpage of this branch of the page tree. 此TypoScript(以及上面的代码段)还将处理TYPO3( SPC )中的菜单分隔符页面,并仅添加Bootstrap的divider元素(如果它不是页面树的此分支的第一子页面)。

 lib.navbar = COA lib.navbar { wrap = <nav class="navbar navbar-default"> <div class="container-fluid"> | </div> </nav> 10 = COA 10 { wrap = <div class="navbar-header"> | </div> 10 = COA 10 { // hamburger icon: wrap = <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">|</button> 10 = TEXT 10.value = <span class="sr-only">Toggle navigation</span> 20 = TEXT 20.value = <span class="icon-bar"></span> 21 < .20 22 < .20 } // company name/logo: 20 = TEXT 20.value = Project name 20.typolink { parameter = http://www.example.org/ ATagParams = class="navbar-brand" } } 20 = HMENU 20 { wrap = <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> | </ul> </div> 1 = TMENU 1 { expAll = 1 NO = 1 NO { ATagTitle.field = title wrapItemAndSub = <li>|</li> } CUR < .NO CUR { wrapItemAndSub = <li class="active">|</li> } ACT < .CUR IFSUB = 1 IFSUB { ATagTitle.field = title ATagParams = class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" linkWrap = |<b class="caret"></b> ATagBeforeWrap = 1 wrapItemAndSub = <li class="dropdown">|</li> } ACTIFSUB < .IFSUB ACTIFSUB { wrapItemAndSub = <li class="dropdown active">|</li> } CURIFSUB < .ACTIFSUB } 2 < .1 2 { // Adjust several classes for sublevels wrap = <ul class="dropdown-menu multi-level">|</ul> IFSUB.wrapItemAndSub = <li class="dropdown-submenu">|</li> ACTIFSUB.wrapItemAndSub = <li class="dropdown-submenu active">|</li> // Remove caret element (correct arrow is set with ::after pseudo element) IFSUB.linkWrap > ACTIFSUB.linkWrap > CURIFSUB < .ACTIFSUB SPC = 1 SPC { // no divider, if first menu item on this level (using optionSplit): wrapItemAndSub = <li class="dropdown-header">|</li> |*| <li class="divider"></li><li class="dropdown-header">|</li> } } 3 < .2 4 < .3 } } 

Please be aware that pages containing sublevels cannot not be linked to a page in TYPO3 this way. 请注意,不能通过这种方式将包含子级别的页面链接到TYPO3中的页面。 You'll need to use Shortcut pages, just as do with these pages on the first level of this navigation. 您需要使用快捷方式页面,就像在导航的第一级上使用这些页面一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM