Condition: Menu has items

Hi guys,

I try to create a template which distinguishes between the case if the submenu has elements or not.

My typoscript looks like this:

parts {
  secondMenu = Menu {
            entryLevel = 2
            maximumLevels = 1

and template:

<div class="col-sm-9" id="main-content">
  <f:if condition="{parts.secondMenu}">
      <div class="col-sm-3">
          {parts.secondMenu -> f:format.raw()}
      <div class="col-sm-8 col-sm-offset-1">
          {content.main -> f:format.raw()}
	{content.main -> f:format.raw()}

What is the correct condition? I tried also {parts.secondMenu.items} or also a different typoscript variables like hasItems = ${q(node).children()}.

Thank you in advance.

Hi Klaus

Problem is that the menu always outputs a wrapper, regardless of being empty.

You can solve it in two ways:

  1. Remove output from menu if it’s empty

    secondMenu.@process.emptyIfNoItems = ${Array.count(this.items) > 0 ? value : ‘’}

  2. You can check if the page has children

    hasItems = ${q(node).closest([’_depth=3’]).children(’[instanceof TYPO3.Neos:Document][_hiddenInIndex = false]’).is()}

Didn’t test this, but should give you some pointers.


First way does not fit my use case and second one results in the following erro:

filter operation expects string argument

But this works:

hasItems = ${q(node).siblings('[instanceof TYPO3.Neos:Document][_hiddenInIndex = false]') && q(node).parents('[instanceof TYPO3.Neos.NodeTypes:Page]')}

Thank you for your help.

Can I close this in any way?

Good to hear. You’re welcome.

Not sure if you’re allowed to do it, but if you are you can click the wrench icon in the bottom fo the thread and select “Close Topic”. Let me know if it’s not possible for you.

I think I am not allowed to do so, because there are only buttons for bookmark, share, reply and watching.

Think this feature would increase productivity of this forum.