Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

typoscript - TYPO3: Add special menu CE and add class="active"

In TYPO3 one can insert a special menu as a content element, you can select about eight different ways to collect the menu.

In the menu I selected there is no class assigned if the menu item is active, and I need to highlight it with CSS. And I'd like to know how to add a custom menu.

Note: Once I did apply the solution supplied in my own answer I realized that the main difficulty was (and generally is in TYPO3) the caching, be aware to refresh frequently otherwise you'll never be sure what is correct code and what isn't...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The answer:


  1. Copy the original fluid template (menu of subpages of selected pages in my case):

    typo3/sysext/fluid_styled_content/Resources/Private/Partials/Menu/Type-1.html
    

    TYPO3 v8: different path and different names

    typo3/sysext/fluid_styled_content/Resources/Private/Templates/xxx.html
    

    To (coherently to the directory you'll declare in point 4)

    EXT:myExtension/Resources/Private/Partials/Menu/Type-1.html
    
  2. Add a variable that gives the current page id in your setup (libs.ts, probably this can be done easier and this value could be present already for use in point 3, but I wouldn't know how to code that).

    lib.pageId = TEXT
    lib.pageId.data = page:uid
    
  3. Edit the template (I just give the applicable condition here)

    <f:if condition="{page.uid} == {f:cObject(typoscriptObjectPath: 'lib.pageId')}">
        ...
    </f:if>
    
  4. Include the new fluid template (I overwrite the original one, keeping the original name)

    TYPO3 v8: use lib.contentElement instead of lib.fluidContent

    lib.fluidContent.partialRootPaths.1920 = EXT:myExtension/Resources/Private/Partials/Menu/
    

    Or as I did, include it in your page-setup

    page = PAGE
    page {
        # Page Main template
        10 = FLUIDTEMPLATE
        10 {
            partialRootPaths = EXT:myExtension/Resources/Private/Partials/Menu/
        }
    }
    
  5. If you'd like to add it as an option to the list you re-number the file (like Type-9.html) and add it to the menu in Page TSConfig:

    TYPO3 v8: i did not find a way to add a menu in v8, the config given here does not work ...

    TCEFORM.tt_content.menu_type {
       types {
          menu{
             addItems {
                9 = menu of subpages of selected pages active highlighted
             }
          }
       }
    }
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...