Is it possible to use this module to set a non-primary menu as active ?
Assigning this setting is possible (every menus are displayed in the settings menu) , but I can't find the way to substitute the menu function in template.php, and don't know if it's ever possible.

Thanks.

Comments

yraber’s picture

Just to be a little more precise, the context is already right , it opens the right menu tree, the only thing that's missing is the "active" tag on the menu list element, so that I can put it in bold.

neurojavi’s picture

Hi:

I've solved this issue using this http://drupal.org/node/77485#comment-433733 to add the active-trail class to the li elements.
This works fine since this module takes care of setting the active trail...

You have to add this to your theme template.php:

function thenameofyouthemehere_menu_item($mid, $children = '', $leaf = TRUE) {
  $active_class = in_array($mid, _menu_get_active_trail()) ? ' active-trail' : '';
  return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . $active_class .'">'. menu_item_link($mid) . $children ."</li>\n";
}

And use something like this in your css (note the > symbol!):

li.active-trail > a {
font-weight:bold;
color:#000000;
}

Perhaps it would be useful to add a note to the documentation about this...

Very useful module!
Many thanks the developer.-

encho’s picture

Strange, does not work with me. If I have a list or node that falls straight under primary menu, it works fine, but when selecting individual node (although its node type is declared in menu trails types and its category too), it does not have 'active' property!

neurojavi’s picture

Hi encho:

If you have included the above code in your theme then you should have an "active-trail" class in your li elements (not an "active" class).
You can change the code to add "active" instead of "active-trail" if you like...

If this is not your problem please be more explicit on what have you done...

encho’s picture

That's exactly what I did. It still does not appear. I am using modified Zen theme. active-trail does not appear anywhere.

neurojavi’s picture

That's strange...

I use a modified zen theme too.
Have you changed the name of the function to match your theme (zen) or subtheme name?
thenameofyouthemehere_menu_item()

I you did it, can you put a echo inside the function (first line) so you can see if the function is called?
The problem can be in the function not being called or in _menu_get_active_trail() not returning the right value...

vistree’s picture

Hey!
Tried your solution together with the menu-trail module.
Works GREAT for Firefox (2) but is ignored by the IE 6.
Is this the same for you?
Tried out with bluemarine theme and the following modifications:
* created a custom menu called "Mainmenu" (to be display as "normal" vertical menu in the left-sidebar!!!)
* installed menutrails-module and used the Mainmenu as parent for primary AND secondary links
* filled the following code in a fresh template.php

<?php

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) { // what function is active?
    case 'page': // page is where menu comes into play
      // set the primary links
      $vars['primary_links'] = menutrails_primary_links(1);
      // you may want to also override secondary_links
      $vars['secondary_links'] = menutrails_primary_links(2);
      break;
  }
  return $vars ;
}


function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
    $active_class = in_array($mid, _menu_get_active_trail()) ? ' active-trail' : '';
  return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . $active_class .'">'. menu_item_link($mid) . $children ."</li>\n";
}

?>

* filled the following code in the existing style.css

li.active-trail > a {
font-weight:bold;
color: #a00000;
}

This works fine for the Firefox but is ignored by IE (I use the version 6.0)
Is there any help?
Regards
Kai

encho’s picture

No output... Can you give me your template.tpl.php (or at least related parts), so I can overwrite my template.tpl.php and try yours? Maybe I have some conflict elsewhere in the template? Still banging my head...

vistree’s picture

Hi encho,
I just tried out with the standard bluemarine template! Try out with one of the original phptemplates ones, too - not with your own as a first step.
Open (or create??) the template.php in the root directory of your theme.
Then include the following code:

<?php

function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) { // what function is active?
case 'page': // page is where menu comes into play
// set the primary links
$vars['primary_links'] = menutrails_primary_links(1);
// you may want to also override secondary_links
$vars['secondary_links'] = menutrails_primary_links(2);
break;
}
return $vars ;
}

function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
$active_class = in_array($mid, _menu_get_active_trail()) ? ' active-trail' : '';
return '
# '. menu_item_link($mid) . $children ."

\n";
}

?>

Be sure of the two important factors:
don't include the starting "" and ending "" twice. So if you modify an existing template.php leaf them away.
Be sure that there are NO characters or linebreaks after the closing "?>" .

Fill in the previous mentioned code in your css.
If this works (don't test with IE!!!) then you know, that there is something else wrong with your theme.

Regards
Kai

vistree’s picture

aaah, and be sure, you name it template.php and not, as mentioned in your post, template.tpl.php!!!!!!!

encho’s picture

template.tpl.php was a typo :-)

It is driving me crazy, still not working... Only thing I could think of was that some other module causes conflict, will try this in another installation as soon as I get some time.

Thanks for your effort though.

neurojavi’s picture

Hi:

What version of zen theme are you using?
Are you modifying a subtheme or the main theme?

Please post here your template.php file

primalmedia’s picture

Many thanks! This worked for me

capellic’s picture

Priority: Normal » Minor

Thank you for posting this! I was in the same boat.

Note that I skipped step #2 in the installation instructions found in the module's README.TXT file - I didn't need it.

For those having problems with the trail showing up on secondary menus, be sure you check your HTML to see if it has the "active-trail" class on the li tag. Then you know it isn't a problem with the code or module, it's a problem with CSS. I had to massage the CSS code a bit to get it to show up and it looks like this:

#block-menu_trim-2 li.active-trail a,
#block-menu_trim-2 li a.active {
color: #008acb;
}

Yes, I am using this in combination with the Menu Trim module - works great! (Maybe this is why I didn't need step #2 - maybe Menu Trim was already doing this?)

sun’s picture

Status: Active » Closed (won't fix)

Sorry, Menu Trails for Drupal 5 is not actively developed/maintained anymore. Only issues containing patches may still be considered. Feel free to re-open this issue if you want to provide a patch.