[support] Add "active" class to menu link

toon severijns toon.severijns at gmail.com
Tue Jun 28 12:23:37 UTC 2011


Hello All,

To highlight a menu item (normal menu) as active when in certain conditions
i want to add a (css) class to the link in question. I tried setting the
menu item as active using menu_set_active_item, but this breaks the local
tasks menu. I tried doing the same using menu_set_item preceded
by menu_local_tasks(0), again this breaks the local tasks. So it seems i
have to add a css class to my menu item. I tried this using the following
hooks, but to no avail:

function my_module_menu_link_alter(&$item, $menu) {
  if($item['link_path'] == 'evaluator/mijn-projecten/personal') {
    $item['options']['alter'] = TRUE;
    $item['options']['attributes']['class'] =
(($item['options']['attributes']['class'])?' ':'') . "active-trail";
  }
}

function my_module_translated_menu_link_alter(&$item, $map) {
  $item['localized_options']['attributes']['class'] .= ' active-trail';
}

Any ideas?

Best,


Toon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110628/31a8175e/attachment.html 


More information about the support mailing list