Friday, September 05, 2008

Drupal Custom Menu

So, you've made a custom drupal menu, now you want to use it in your theme. How do you use your custom drupal menu in a theme? Here's how.

First, Drupal adds "menu-" to your custom menu. So if you named your menu "custom-menu", when referencing your custom menu you have to call it "menu-custom-menu".

The drupal api call to make is "menu_navigation_links", and then pass the result to "theme" to render the list.

print theme('links', menu_navigation_links('menu-custom-menu',0));

Look how the code above is similar to what you're used to doing for the $primary_links, and $secondary_links that are built into drupal, as shown below:

print theme('links', $primary_links, array('class' => 'links primary-links'));

2 comments:

Sarah said...

Superstar..thank you very much for this post. The one line I needed and no hair-pulling involved.

yuvi said...

Not sure why it worked, but it worked!!
Thanks a lot!

:-)