Weird i know but as per the clients request i need to do the following:

if node being view is in a directory like this /panelist/panelist-name

or this


i need to set the a menu link in the main menu to active and also a sidebar menu item too.

now i know how to do the javascript part but i don't know to determine if /panelist/ or /moderator/ are in the URL, and also where i would put such code? i guess in template.php?

i tried doing in Rules but it didn't seem possible (still kind of new though!)

pseudo code would be if node being viewed contains 'panelist' or 'moderator' in URL then echo out some javacript or set some menu item class to 'active'

much thanks!

1 Answer 1


Something like this in your theme template can work:

function MYTHEME_preprocess_menu_link(&$variables) {
  if (menu_get_object()) {
    $parsed_path = explode('/', drupal_get_path_alias());
    $parsed_link = explode('/', drupal_get_path_alias($variables['element']['#href']));

    if (some_compare_func($parsed_path, $parsed_link)) {
      $variables['element']['#attributes']['class'][] ='active-trail';

You will have to implement some_compare_func yourself, or use a regular expression instead of exploding items, to do whatever matching needs to be done.

You can also check which menu the link belongs to (['#original_link']['menu_name'])

This is just a primer to get you going.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.