I am using the "same menu for secondary links as for primary links" feature to get very nice drill down behavior from my primary-links to the children of those links. Keeping all my navigation in one menu makes sense to me but I am running into problems when my secondary-links have children of their own. I have seen mention of this sporadically in the articles but nothing conclusive I could find.
I think I am close to a solution. I am currently do this with my secondary-links in may page.tpl.php ...
print theme('links', $secondary_links);
I think I understand that this is not going to work as the 'links' are not a tree of data, rather a list of data.
So I tried this:
$menu_name = variable_get('menu_secondary_links_source', 'secondary-links');
print menu_tree($menu_name);
Which is close to what I want, but because the secondary links are the same as the primary links this gives me the whole menu structure instead of the menu structure from the currently selected top level item down. So what I would really like is a function that let me specify the parent to start at when building the menu tree.
Does anyone know of such a function/data structure/etc that could be used for this?
Thanks for any help you can provide.
cheers -d
Comments
hackintoshian solution
So I came up with a workable solution for my needs as follows ...
The menu_tree function does pretty much what I need in terms of highlighting the right nodes, expanding the current path etc. The only problem was that it was including the top level of the navigation tree as well. I needed some way to extract the current second level menu from the whole. This is what I did:
Now I should probably cache the results of this and there might be a better place to put the code then in the page.tpl.php but I am quite happy to have it working and I am really amazed that there is not a core function that does this. Something like menu_tree_level($menu_name = 'navigation', depth_from _parent = 0); so that you could get the tree at 1, 2, 3, etc levels from the parent relative to the currently selected page.
Seems useful to me anyway...
-d
Wow, interesting to see you
Wow, interesting to see you working on this the day before I start looking for it. I'm also kind of dumb-founded that there is no core functionality for 3rd level links for primary and secondary. It's a major limitation for site design to not have a good easy method to display a 3rd layer of links. I'm going to give your code a spin and hope for the best.
...
There is. (If I understand you correctly.) It's called menu_navigation_links(). Example:
Rock on!
Man, I've been searching for so long for a solution to that problem ! Tried out your code and it does seem to work. Thanks !
I blog about Drupal right here
Nice solution. Works great!
Nice solution. Works great!
Thanks!
Thanks a lot for this code. I had spent several hours trying to figure out how to display secondary links as a tree menu before stumbling upon your solution. Of course as you point it out, page.tpl.php might not be the best place for it. I've put it in template.php using a "preprocess" function:
Then in page.tpl.php I just display the menu this way:
print $secondary_links;where I want it to appear in the page.
Is there also a way to get a
Is there also a way to get a single level output not via preprocess, but inside a block?
I just use this code in a PHP
I just use this code in a PHP block
This is a livesafer. Thanks!
This is a livesafer. Thanks!
Mimic secondary navigation links
I struggled with this for a while as well, so here's my solution. It mimics the functionality where the secondary menu is the children of the active link in the main menu, but maintains a tree'd display.
First, thanks to @simonderevo adn @FMB. I borrowed your ideas above and modified them a little.
Then, in your page.tpl.php, simply render the variable
* Side note, I just tried this with a custom menu and the "below" value was not set on active items when there were clearly items defined. However, when switching to the default Main Menu, the "below" array was set. I haven't looked deeply into this yet.
--------
Chris (KeyboardCowboy) - @ChrisAlbrecht