Hi
I am trying to create a new theme based on Omega 960 for Drupal 7. For the menus I am trying to use a variation of the sliding doors technique to include one level of submenus. You can see the site at www.letsgoagile.com

Currently I have used pure CSS to display the sub menu correctly when I hover over a top level item which has another level (blogs). Naturally I would like the sub menu to remain active when I select its parent. Problem is I can't because the class = "active" is set against the link rather than the list item. I.e. <li class="expanded"><a href="/blog" title="" class="active">Blogs</a><ul class="menu">...

I can identify which is the active item by using (in theme_menu_link()):

$output = l($element['#title'], $element['#href'], $element['#localized_options']);
if (stristr($output, 'active')){ ...

Trouble is what do I do with it then. In my example drupal_attributes($element['#attributes']) returns class="expanded" which is applied to the li element. I would like to modify this to include active (class = "expanded active").

Any ideas how to do this?

Apologies if this is obvious - I am brand new to theming, php and CSS :-)

Comments

seangee’s picture

This is working for me:

function MYTHEMENAME_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);

  if (stristr($output, 'class="active"')){
     $element['#attributes']['class'][] = 'active';
  }

  return '<li' . drupal_attributes($element['#attributes']) . '>' .$output . $sub_menu . "</li>\n";
}

Now I just have to figure out how to make the parent li active when I select a child :-)

seangee’s picture

Didn't realise the default menu behave differently to those I created (why???).
Active-trail met all of my needs and its back to straight CSS. At least I learnt how the over-ride system works and excercised some very rusty php skills along the way.