I'm a newbie to Drupal, and building out a first theme. I'd built an intended design in basic html and now I'm converting it to a theme. I'm stuck at the main menu with dropdowns.

I've seen there are two basic ways to add a menu, but both have problems that I'm stumped on.

Method one was to do something along this line:

<?php if ($main_menu): 

print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu')));
endif;
?>

This worked, but the dropdowns wouldn't appear. I did check to make sure both the main menu and submenus were set to expand. I cleared cache. Nothing mattered.

The second method seems to be making a menu block:

  <?php if (!empty($page['main_menu'])): 

print render($page['main_menu']);
endif;
?>

This method got me closer. It prints the menu and all the submenu. A couple tweaks to my css can generate close to what I want. But It's still not quite there. It would be perfect if I could change the class and id of the menu components.

What I get is this:


<ul class="menu">
  <li class="first expanded">
   <a href="/" title="" class="active">MainLink w. dropdowns</a>
    <ul class="menu">
       <li class="first leaf"><a href="/" title="" class="active">Submenu 1</a></li>
       <li class="last leaf"><a href="/" title="" class="active">Submenu 2</a></li>
     </ul>
   </li>
<li class="leaf"><a href="/" title="" class="active">Mainlink 2</a></li>
<li class="leaf"><a href="/" title="" class="active">Mainlink 3</a></li>
<li class="leaf"><a href="/" title="" class="active">Mainlink 4</a></li>
<li class="leaf"><a href="/" title="" class="active">Mainlink 5</a></li>
<li class="last leaf"><a href="/" title="" class="active">Mainlink 6</a></li>
</ul>

If I could just get rid of "leaf" class and get rid of / change the submenu class "menu", I'd be right where I need. Heck, it'd be nice to change the main ul to a different class as well.

I've searched around and not found something clearcut and understandable. There are a lot of seemingly more complicated answers to what I assume would be a very simple solution. I'd prefer not to use any add-ons to do this.

Comments

tangofan’s picture

I think you can do this by overriding a theme function in your template.php file.
Check out this discussion about adding and removing classes to menus: https://www.drupal.org/node/2295461