I'm using Drupal 7 and the Bootstrap theme. In the template.php file, I am successfully theming the primary menu (main menu) to enable extra list styles with the following code.

function MYTHEME_menu_tree__primary($variables) {
  return '<ul class="custom-style">' . $variables['tree'] . '</ul>';

I would also like to theme a new menu (menu-banner), but I can't access it as expected, with the following code.

function MYTHEME_menu_tree__menu_banner($variables) {
  return '<ul class="custom-style">' . $variables['tree'] . '</ul>';

The new menu is successfully defined in MYTHEME_preprocess_page() in the template.php file.

$menu = menu_navigation_links('menu-banner');
$vars['banner_nav'] = theme('links__menu_banner', array('links' => $menu));

I'm able to render it as banner_nav in the page templates.

Is there something I'm missing, or is there something specific to Bootstrap that is different from what reported from theme_menu_tree() documentation?


This isn't related to Bootstrap. In your preprocessor you're using theme_links, which is unrelated to menus. Your "menu" isn't being output as a menu at all.

If page preprocessing is necessary, you can try:

function THEMENAME_preprocess_page(&$vars) {
  $menu = menu_tree_all_data('menu-banner');
  $vars['banner_nav'] = menu_tree_output($menu);

Or you can render the menu block (these are automatically generated if you have the Blocks module enabled):

function THEMENAME_preprocess_page(&$vars) {
  $block = block_load('menu', 'menu-banner');
  $vars['banner_nav'] = _block_get_renderable_array(_block_render_blocks(array($block)));

In page.tpl.php:

<?php print render($banner_nav); ?>

Either will work.

If you don't need to preprocess the menu, you can simply position it via the Blocks admin UI.

I hope that helps!

  • Thanks!, I'll give it a go. In the meantime, I was able to get it working using the secondary navigation instead of a custom menu, which is good sort of. My main motivation with this is to get to a place where I can re-use classes instead of having a ziggurat of rules for similarly styled things like menus that are mostly the same design.
    – david w.
    May 23 '15 at 0:47

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.