Navigation Menu collapse once I drill down to a node.
Hi All,
I have a installation of drupal 5.x using the garland theme with CCK and views module installed. I have created the menu structure, like so:
About Company XYZ
Expanding Link 1
Expanding Link 2
Meet The Team
Primary Link 2
Primary Link 3
The Meet the Team menu item is configured with a path to a custom view which displays a table of team member content types. When I click on an item in the table it takes me to that content item using the normal drupal url e.g node/3 however the navigation collapses meaning I no longer know that I'm in the Meet the Team section.
This only seems to happen once the navigation is 2 levels deep. So a standard page content item linked to Expanding Link 1 manages to retain the correct menu structure.
My question is how does a content item automatically tell the menu system which section it belongs to so the menu knows which sections to expand/collapse.
Thanks for any help, pointers for this problem
Rich

I'll just add some html to clairfy the menu structure I mean.
I had this problem
I had this problem too with a site that I'm developing. I managed to fix it by adding some code to the custom module for the site. I don't know whether there is an 'easier' or more official solution to this - but I would love to know if there is!
In this code the content types I check for are 'news' and 'simplenews', but you could use taxonomy or some other means of enabling the node.
The path 'news' is the path to the menu item I want to expand, and '/node/nid' is obviously the path to the node. You can insert more nodes into the array - this also builds a breadcrumb for the page. For example in a larger site I might have used 'news', 'news/press' and 'news/press/latest' if I had that many levels of menu :)
Well I hope that was useful to you, or drop me a line if you want some help.
<?php
// this function expands the 'newsroom' menu item when you are viewing a 'news' node
function pastels_nodeapi($node, $op,$teaser = NULL, $a4 = NULL) {
if ( ($op == 'view') && !$teaser ) {
switch ($node->type) {
case 'news':
case 'simplenews':
$items[] = array(
'path' => 'news',
);
$items[] = array (
'path' => 'node/' . $node->nid,
);
menu_set_location($items);
break;
}
}
}
?>
menu_set_active_item seems to work for me
Hi Dave,
Thanks for your reply. Glad its not just me having this issue, I ended up using similar code to yours but using menu_set_active_item instead of menu_set_location.
menu_set_active_item takes a string of the current menu you want to expand the menu to, and the menu system takes care of the rest.
I call this function from within node_view using a switch as follows:
switch($node->type) {case 'team_member': {
menu_set_active_item('about/team_members');
break;
}
case 'press_release': {
menu_set_active_item('media/press_releases');
break;
}
}
Cheers
Rich
Ah, I see menu_set_location
Ah, I see menu_set_location calls menu_set_active item! The only thing is menu_set_location adds the breadcrumbs that I need and menu_set_active_item doesn't appear to do that.
I'd also like to do the same with views
I'd also like to do the same with views but am not having much luck.
I was expecting placing the following code in the function views_build_view in views.module would have the same effect of forcing the menu to expand to the desired pathbut it seems to be getting overridden later.
switch($view->name) {case 'Regional_Contact_Details': {
menu_set_active_item('about/team_members');
break;
}
}
Any suggestions?
Are you editing
Are you editing views.module? you really shouldn't hack drupal core. The correct way to extend drupal is to create your own module and use the various hooks to alter the behaviours you need. In my code I used the nodeapi hook to execute code whenever a node is viewed.
The correct way to do things...
Thanks for you pointers dave.
I have done as you suggested and created a custom module with the required code in a nodeapi hook and it seems to be working pretty well.
Cheers
No problem. You will be
No problem. You will be glad of it when you upgrade to the next version of views and don't lose all your modifications :)
To have my Advanced Search back
Hi all, first thanks for the info.
But my Advanced Search then disappeared.
To have my Advanced Search back, I put ($a4==true) as an additional condition, meaning that it applies only to node displayed itself in a page, doesn't it? Well, this seems working
function myhook_nodeapi($node, $op,$teaser = NULL, $a4 = NULL) {if ( ($op == 'view') && !$teaser && $a4==true ) {
...
Thanks
The menu trails module also addresses this
http://drupal.org/project/menutrails
ourbrisbane.com
Question
I have a similar problem and tried using menu trials but it doesn't work for me.
so my menu system is like this
menu 1
--current1
--past1
menu 2
--current2
--past2
menu 3
--current3
--past3
current and past submenus are nodes based on views. Once you go inside, let's say, current1, you'll see teasers but once you go inside one of these, the whole menu collapses. Is there anyway to keep the menu expanded??
I think the solution will be a custom module. If so, can someone share the module with me and I'll customize it to my needs?
What did you end up using Rich?
Thanks!
JL
you don't need coding
just be aware of the menu entry fields when creating the node. If you set the options for the menu there the menu tree will keep expanded when a node is viewed.
roger