2

I need to show a menu which only displays nodes one or two levels into the menu hierarchy, unless these nodes are immediate children of the node currently being viewed, in which case they should also be shown. (I explain what I'm after more fully in the lengthy 'example' below.) The Menu Block module almost lets me do this, but lacks a setting to expand the immediate children of active item. I added this as a feature request for Menu Block but have had no reply. Is there any way I can implement this myself, either using Menu Block or writing code to display the menus myself? Any code pointers would be very helpful.

(Background info: I'm using Drupal 7)

An example of what I'm after

Suppose you have a menu with these items (with the number of dashes before them representing their level):

-i1
--i2
--i3
---i4
---i5
----i6
--i7

If in Menu Block I set my menu block up with 'Starting level' = '1st level' and 'Maximum depth'=1 then it'll look like:

-i1
--i2
--i3
--i7

However, I'd like there to be an 'expand the immediate children of the active item' setting in Menu Block. If this setting were chosen then if the active item were i3 or i4 you should see:

-i1
--i2
--i3
---i4
---i5
--i7

And if it were i5 or i6 you'd see:

-i1
--i2
--i3
---i4
---i5
----i6
--i7
9
  • Isn't this pretty much what you would get with a unlimited maximum depth menu?
    – Madis
    Commented May 1, 2012 at 20:42
  • does it apply to D7? There are no tags now related to the actual Drupal version. :)
    – Sk8erPeter
    Commented May 2, 2012 at 11:52
  • @Sk8erPeter yes (though I was following this site's guideline that 'Version tags should be used only when strictly necessary, and not used just to report "I am using Drupal 7 in my site."' :-)
    – tog22
    Commented May 2, 2012 at 14:49
  • @Dooshta No it's not - if you look at cea-gwwc-alex1.philosofiles.com/resources/… you'll see nodes like 'health' showing in the Menu Block in the red left sidebar. This Menu Block has 'Maximum depth' set to 'Unlimited'. You can therefore see the root menu items grandchildren like 'Health', but I don't want you to be able to unless you're on the 'Charity Comparisons' page, or indeed the 'Health' page. So as you can see 'Maximum depth'='Unlimited' doesn't achieve this.
    – tog22
    Commented May 2, 2012 at 14:54
  • @tog22: if you think about this one, there's another sentence too: "Use 7 only on questions that are specific for features implemented in Drupal 7." - and your question can be a version-specific problem as the code you have to apply for doing these modifications can hugely depend on Drupal's version. I think the suggestion not setting version-specific tags can refer to general questions like "suggestions to boost Drupal's performance", etc.
    – Sk8erPeter
    Commented May 2, 2012 at 15:10

1 Answer 1

2

Like we figured out in the comments the problem was that the "Expand all children of this tree" option was checked for the menu block. Without checking this the children will only be shown if the user is on a related page, which was the desired result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.