making a section title, above a menu

Events happening in the community are now at Drupal community events on www.drupal.org.
nadavoid's picture

Theming question here...

I have a $secondary_menu in my page.tpl.php and it's doing what it's supposed to. Right above it I have a Section Title. I want that section title to be replaced with whatever the top-level menu item is. (Say the top-level is About | Products | Contact, and then 2nd level under Products is Shoes | Coats | Umbrellas. If you've clicked on Umbrellas, I want the section title to be Products.)

I've found this link http://drupal.org/node/23348 and it might sorta work for me. The problem is that the best thing suggested in that post is based on path alias. I'd much prefer that it be based completely on the menu structure.

I'd like to find a function that does something like this:
menu_get_text($level=1);
but I'm having difficulty finding something that will do that.

Any tips? (or probably someone has already posted exactly this solution, and I just haven't found it yet.)

Comments

D5's menu_get_active_trail

chrisfromredfin's picture

menu_get_active_trail is an API function that will return the active trail. so, from there, you should be able to figure on the title of the parent menu item, and print it.

.cw.

got it!

nadavoid's picture

I've got it working. Thanks for the pointer. That was exactly what I needed. Here's how I fleshed it out. (this is based on a the zen theme)

In template.php -> function _phptemplate_variables() -> case 'page'
I added this:

// Set the section_title
$title_temp = array();
$title_temp['trail'] = _menu_get_active_trail();
$title_temp['menu'] = menu_get_item( $title_temp['trail'][1] );
$vars['section_title'] = $title_temp['menu']['title'];
unset($title_temp);

Then in my page.tpl.php, I can use $section_title. perfect!

So now, a "best-practices" question... I created a temporary variable $title_temp to hold the output of the functions, just long enough to grab what I needed. Is there a standard variable or practice, to use for holding temporary data in template.php?

hey nadavoid, thanks for

fcsoares's picture

hey nadavoid, thanks for sharing your solution. I really like the way you use an array to handle mutiple variables and how you have just a single variable to get rid off when finish using the temporary data. again, thanks!