Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
i'd like to control a menu block's visibility based on the depth of the current page.
does menu block provide a function that makes it easy to figure out what the depth is of the menu link that corresponds to the current page? or do i just need to query the menu_links table myself?
would anyone else be interested in a visibilty based on depth feature? or maybe a "ending level will be" configuration to correspond to "starting level will be"?
thanks!
Comments
Comment #1
dilari CreditAttribution: dilari commentedCan you not achieve that by setting the starting level and maximum depth ?
i.e. starting level '2nd level' and maximum depth '1'
Comment #2
firebus CreditAttribution: firebus commentedno. max depth controls how many levels of menu the menu block displays (e.g. maxdepth = 1 means that no expanded children will be displayed in the menu block).
max depth has nothing to do with whether or not the menu block is visible at a given depth.
so if you set starting level to 2nd, you'll see the menu block on any menu item that is 2nd level or deeper.
depending on whether or not you check "Make the starting level follow the active menu item.", the menu block will follow you down, or will stay anchored at the 2nd level.
Comment #3
dilari CreditAttribution: dilari commentedYou're right, your suggestion for the 'ending level' is what is missing;
You can make it follow but you can't not display it.
Would be best if it where possible to set visibillity per level.
So: show on level 1, don't show on level 2 & 3 , show on level 4
You could , not dynamically though, set it to not display on certain pages in your block contig.
Comment #4
JohnAlbin