Access the currentLevel in a TYPO3:Neos:Menu

Hey,

any solution so far to access the current level in a menu? @aertmann mentioned the {item.node.depth} but this shows the current level of the node in your whole tree and not the current level in your menu.
I’d like to access the current level of the menu. Is there maybe a way to access the current level with some eel magic? Or is this already possible?

Another possible solution could be to extend MenuImplementation class ( see https://jira.neos.io/browse/NEOS-1375 ) .
I also thought about a solution to pass a custom var in fluid to <f:render section="itemsList" arguments="{items:item.subItems, currentLevel: {currentLevel}+1} but of course you need another ViewHelper to do the +1 for you.

So is there maybe already a solution ?

You could probably do it with TypoScript with s.th. like {ts:render(path: level, context: {item: item})} and level = ${item.depth + this.startingLevel}

1 Like

Yeah, got it working with TS.

But two more questions:

  • shouldn’t be the current level a core feature as you will use it a lot
  • if you got some nodes in between that are hidden in menue, depth will show the wrong level, right? Since depth shows us the level in the node structure but not the menu level

Good to hear.

I’m not sure about the hidden nodes, depends on how you did it the calculation…

Regarding being a core feature, it could be. Let’s see if it gets many votes in Jira or attention in this thread maybe. Or if someone from the team decides to merge it.

Hey there,
just chiming in for:

I never felt the need for this and I’m curious: What is your usecase?

In my special case our frontend devs use classes like navigation–level-3 or navigation–level-3 (based on BEM & SASS syntax) inside a menu. This is especially handy if you got a menu with lot of levels to easy trigger your js and style different levels in your menu.

Not trying to convert you, but wouldn’t you do such things with CSS directly nowadays (nav ul ul …)?

Yes, of course. But from my understanding, i’m not a FE dev tough, we aim to get the nestings in a scss file as small as possible. We limit this to 3 at all to get the code cleaner, easier to read and compiling is a lot faster.
I’m not sure if BEM describes how deep you should nest your scss code at all.
In the end it really depends on your project. We got a new project running with 7 menu levels. Depending on the lvl there are different animations. So it’s a lot easier (maybe also faster?!) to select jQuery(‘.navigation–level-3’) instead of jQuery(‘nav ul ul ul’). Same for styling.

It would also be possible to do something like <f:if condition="{item.currentLevel} < 3"> to render another partial or change your HTML structure - if this is needed.

Hey,

sorry to bring this thread up, but is this feature already available?

Cheers,
Ben