I've cruised around the web and it is not at all obvious how to theme custom menus. I've looked for hours and have not found one single post that illustrates the process, from start to finish, of creating a menu and customizing its output. It seems like this is a multi-stage process:
- Create the menu through the Drupal interface.
- Create a theme function in your
template.php
file to theme the output. - Expose this menu to a template file (somehow) by adding it as a variable.
- Call the
theme
function on the menu in the template file.
1 is easy enough to do, the problems I run into are with 2, 3, and 4. Looking at the default page template, I see that it exposes the main menu in the variable $main_menu
. Later down the page you can see the function theme('links__system_main_menu', array('links' => $main_menu...
, which means it's looking for an appropriately named theme function somewhere and using it to generate the output.
I know if I place function theme_links__system_main_menu(&$variables) {...}
in my template.php file Drupal will use that function as opposed to function theme_menu_links(&$variables) {...}
.
What I don't know is how Drupal links the custom menu I created with that function. Let's say for example that I created a menu called My Menu
. Could I create the following function in my template.php
file and theme the output for that menu? function theme_links__system_my_menu(&$variables) {...}
Also, how does one make that custom menu available to a template file? How does Drupal expose the $main_menu
variable to page.tpl.php?
I think the key I'm missing here is how to embed the variable that represents my custom menu into a template page. For the most part though I'm completely lost with what to do after having created the menu.
Thanks for the help.
EDIT: Probably should post what I'm doing. Per my comment to BetaRide below, I need to inject customized HTML into the <li>
elements of the menu items. Specifically, I'm adding Twitter Bootstrap icons.