Hi,

I am trying to get active class on my custom menu, when context rules are true. I tried to add a variable to use it as a placeholder for the additional class passed through drupal and context in particular. I am using a additional span to hold the menuitem descrption so I need the active class on the div with the primary class menu-bg

My current menu_link function in the template.php is here: http://pastebin.com/Cc4KC3vh

Comments

Tux’s picture

I solved it with the following code:

function themename_menu_link(array $variables) {
  $element = $variables['element'];
  $output_first = '';
  $sub_menu = '';
  $element['#localized_options']['html'] = TRUE;
  
  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }

  /**
   * Add menu item's description below the menu title
   * Source: fusiondrupalthemes.com/forum/using-fusion/descriptions-under-main-menu
   */
  if ($element['#original_link']['menu_name'] == "main-menu" && isset($element['#localized_options']['attributes']['title'])){
	$attributes = drupal_attributes($element['#attributes']);
	$check = 'active-trail';
	$classes = '';
	if (strpos($attributes,$check) !== false) { $classes = 'active-trail'; }
	$output_first = '<span>' . $element['#title'] . '</span><span class="menu-descr">' . $element['#localized_options']['attributes']['title'] . '</span><div class="menu-item '.$classes.'"></div>';
  }
  
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li><a href="' . url($element['#href']) . '"><div class="color-2">' . $output_first . $sub_menu . "</a></div></li>\n";
}
paulocs’s picture

Issue summary: View changes

Thanks for adding you solution Tux!

paulocs’s picture

Status: Active » Fixed
paulocs’s picture

Status: Fixed » Closed (fixed)