Skip to content

Instantly share code, notes, and snippets.

@avionbg
Forked from NamelessCoder/Menu.html
Last active May 13, 2018 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avionbg/9af0e26bdef69a2c7517ca95a6b32c79 to your computer and use it in GitHub Desktop.
Save avionbg/9af0e26bdef69a2c7517ca95a6b32c79 to your computer and use it in GitHub Desktop.
Rendering manual menus with VHS
<div xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers">
<!-- By setting the "as" argument, we create a new variable accessible inside tag content -->
<v:page.menu as="myMenuVariable">
<ol class="mySpecialMenu">
<f:for each="{myMenuVariable}" as="menuPage">
<li>
<!-- A few key properties are added on {menuPage} for user friendliness -->
<!-- These are: "linktext", "link", "active", "current", "hasSubPages" -->
<f:if condition="{menuPage.current}">
<f:then>
<!-- Special rendering of "current" page title as raw text -->
{menuPage.linktext}
<!-- And with a conditional next level menu using auto rendering: -->
<v:variable.set name="hasSub" value="{v:condition.page.hasSubpages(then: 'TRUE', else: 'FALSE', pageUid: '{item.uid}', includeHidden: 0, showHiddenInMenu: 0)}" />
<f:if condition="{hasSub} =='TRUE' ">
<v:page.menu pageUid="{menuPage.uid}" />
</f:if>
</f:then>
<f:else>
<!-- There are two common methods of rendering the page links: -->
<!-- Using f:link.page which will re-create the "link" HREF -->
<f:link.page pageUid="{menuPage.uid}" class="{menuPage.class}">{menuPage.linktext}</f:link.page>
<!-- Or with manual link tags using pre-built "link" HREF -->
<a href="{menuPage.link}" class="{menuPage.class}">{menuPage.linktext}</a>
</f:else>
</f:if>
</li>
</f:for>
</ol>
</v:page>
<!-- Note that the {myMenuVariable} no longer exists since the variables are cleaned after tag finishes -->
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment