0

I try this code, but i get only the same default depth for all UL tags.

function MYTHEME_preprocess_menu_tree_override(&$variables) {
  $variables['tree_raw'] = $variables['tree'];
}

function MYTHEME_menu_tree($variables) {
  $menu_level = isset($variables['tree_raw']['#depth']) ? $variables['tree_raw']['#depth'] : 1;
  $class = "menu menu-lvl-".$menu_level;
  return '<ul class="menu clearfix'.$class.'">' . $variables['tree'] . '</ul>';
}

1 Answer 1

1

For Drupal 7.

MYTHEME_menu_link(array $variables) {
  global $_current_menu_depth;
  $element = $variables['element'];
  $_current_menu_depth = $element['#original_link']['depth'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

function MYTHEME_menu_tree($variables) {
  global $_current_menu_depth;
  return '<ul class="menu menu--'.$_current_menu_depth.'">' . $variables['tree'] . '</ul>';
}

NOTE! I noticed this breaks in some cases. I had a three levels deep menu and the second level menu was marked as third.

Your Answer

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

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