CINDUG: Using the menu tree in the theme

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
cjdavis's picture

I have a site I am working on where I need to change the page banner based on which part of the primary menu tree the page is located in. The company has two divisions, and if the current page is anywhere in the 'division A' menus, I want to use one set of code, and if it's in 'division B' menus, I want to use another set.

I started looking into menu_get_active_trail(), but that doesnt appear to be returning useable data. Maybe I am trying to use it in the wrong context, as part of the page.tpl.php?

Any suggestions or ideas?

Thanks,
Chris

Comments

Some thoughts on non coding

dunkoh's picture

Some thoughts on non coding options...

prepend path to drupal project (since crazy spam filter won't let me paste any links!)

context ( I haven't used this yet...)

sections (this one I looked at once before and tried it out, it was ok)

Off the top of my head this

TimNorman's picture

Off the top of my head this sounds like a job for views to me, but then again that is where I always seem to start. My thinking is placing these 2 graphics into a special content type and then using an argument based on the url of the current page to decide which one to display. Not sure if that works but that is the first thing that hits me.

If menu_get_active_trail() isn't giving the data you are looking for what is it not doing?

Seems like what you are doing should work. I assume you are using Drupal 6 as menu_get_active_trail() isn't in Drupal 5 or earlier according to Drupal api.

I'm not a Drupal genius by any means so take any of this with a grain of salt.

active trail looks to the navigation menu

derekwebb1's picture

Hey Chris,

The menu_get_active_trail function generally only pulls information about "This node's" location in the navigation menu. So if you put your sections in a menu other than the nav... well menu_get_active_trail is going to be somewhat less than useful. Correct me if I am wrong on that though...

You may have better luck with menu_get_active_item()

See: http://drupal.org/node/108446

Cheers, Derek

If you are using URL aliases

linclark.research's picture

If you are using URL aliases based on your menu tree, then you should be able to use a preprocess function to create page template suggestions based on the path.

In the book Front End Drupal there is an explanation of how to do this starting on page 133.

(They also recommend sections module)