1

I am working on Drupal 7 project (omega 4 subtheme) with panels and views. I need to assign ID an ID (id="nav") to a DIV that wraps main menu UL. It is a child of div.l-region--navigation. It's the second row of the example bellow.

<div class="l-region l-region--navigation">
<div class="panel-pane pane-block pane-system-main-menu">
    <ul class="menu">
        <li><a href="home">Home</a></li>
        <li><a href="home">Home</a></li>
    </ul>    
</div>

Anyone knows how to do this? Is there a specific drupal way of doing this?

3
function mytheme_links__system_main_menu($variables) {
$site_frontpage = variable_get('site_frontpage', 'node');
  $html = "<nav id='main-nav' class='animate'>\n";
  foreach ($variables['links'] as $link) {
      if($link['href'] == '<front>') {
        $html .= "<a class='1' href='" .$site_frontpage ."'>" .$link['title'] ."</a>";
      }
      else {
        $html .= "<a class='2' href='" .$link['href'] ."'>" .$link['title'] ."</a>";
      }
  }
  $html .= "</nav>\n";

  return $html;
}

The code can be used in template.php to override the output of the . However, the only variable it seems to accept is $tree, which prints out all the contents of a and so is not very helpful.

  • I agree - not very helpful indeed. – Zel Jul 21 '14 at 16:20
1

You can simply achieve that using the Menu attributes module

This simple module allows you to specify some additional attributes for menu items such as id, name, class, style, and rel.

  • This sounds pretty much what I need. BTW, do you know can I target the wrapping DIV or only Menu Items such as <li>? – Zel Jul 21 '14 at 13:39
  • @ Krishna Mohan, I checked the module and it allows additional attributes only on link items (a:). That's nice but not what I need. – Zel Jul 21 '14 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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