2

How can I check where in a menu tree a node is, and in particular how can I determine what its ultimate parent is? And how can I display a portion of a menu tree? Here's an example menu tree to illustrate:

m1
-subm2
--subsubm3
-subm4
m5
-subm6

If I were on the pages linked to from items 1-4, I'd want to find out that the ultimate parent of these items is m1, and then display only the portion of the menu below m1, ie:

m1
-subm2
--subsubm3
-subm4
5

I am pretty sure Menu Block will do what you need. I have used this module to display portions of menus only under one parent item as you mention and it worked great. It's for Drupal 6 & 7 as well.

  • Upvoted as that seems a brilliant answer to my 2nd question as I can extract the relevant code from the module - thanks! Would still love an answer from anyone to my 1st question: "How can I check where in a menu tree a node is, and in particular how can I determine what it's ultimate parent is?" – tog22 Feb 7 '12 at 12:44
  • Glad Menu Block will do the trick. As for your first question, I'm not sure, but could it be possible to do a query for the menu's active trail / acive item (which is embedded in the rendered HTML) with JQuery and then spit that back out? Just a shot in the dark. – Danny Englander Feb 7 '12 at 17:04
  • Clever idea! But that'd get inelegant and complicated - I'd have to print all the possible sub-trees, hide them with CSS, and then unhide one with JQuery. So I'll hold out for someone coming up with a way to do this with PHP. – tog22 Feb 8 '12 at 14:10
  • Now I'm not sure how this differs than what you are trying to do with Menu Block. For example, that can print out subtrees as a sidebar block. – Danny Englander Feb 8 '12 at 15:47
  • I'm not sure how you're not sure :) My outstanding 1st question was: "How can I check where in a menu tree a node is, and in particular how can I determine what it's ultimate parent is?" Your answer in your comment was to write some jquery which'd detect the active item and show only the menu portion containing it, but I thought that sounded a bit complex. – tog22 Mar 2 '12 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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