D
D
Dmitry Kamyannoy2015-03-15 14:16:29
Drupal
Dmitry Kamyannoy, 2015-03-15 14:16:29

How to add a class to a child ul?

Good afternoon. I'm interested in the actual question:
I created a mega menu, but one class for ul had to be defined in jquery, but I'm not very happy with it, because while the page is loading, it looks disgusting.
I found this feature

function имя_menu_tree__main_menu($variables) {
  return '<ul class="каокй-то класс">' . $variables['tree'] . '</ul>';
}

But it only adds the class to the main ul element.
More details in the picture :
4Ak3y50Sbkz8Aq.jpg
I also tried the menu atribute module, but it can only add classes to the a and li tags
Thank you very much =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Drupby, 2015-03-15
@drupby

You need to add something like this code to the template.php file of the theme

function ИМЯТЕМЫ_menu_link__ИМЯМЕНЮ($variables) {
  $element = $variables['element'];
  $sub_menu = '';
  // Задаем условие по пункту меню 
  if ($element['#original_link']['mlid'] == 482) {
    // Указываем функцию темизации
    $element['#below']['#theme_wrappers'] = array('menu_tree__one_link');
  }

  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 ИМЯТЕМЫ_menu_tree__one_link($variables) {
  return '<ul class="myclass">' . $variables['tree'] . '</ul>';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question