Drupal Override Custom Menu Template

前端 未结 4 1807
挽巷
挽巷 2020-12-08 16:23

I created a custom menu called \"sub-top-nav\" and now I\'d like to override the html output. In particular I would like to add an unique class to each item like.

Th

4条回答
  •  执念已碎
    2020-12-08 16:45

    After looking through the API I finally found an easy solution to tag the root menu with the same class (this is useful to style only the top level menus uniquely, while maintaining them dynamically friendly). Simply use the plid instead of mlid. I noticed the plid is always 0 for top level menus.

    function theme_menu_link(array $variables) {
      $element = $variables['element'];
      $sub_menu = '';
    
      $element['#attributes']['class'][] = 'menu-' . $element['#original_link']['plid'];
    
      if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
      }
    
      $output = l($element['#title'], $element['#href'], $element['#localized_options']);
            $count = 1;
      return '' . $output . $sub_menu . "
  • \n"; }

提交回复
热议问题