User login

Printing an arbitrary menu just like primary_links and secondary_links

Searched words: 
print another menu like primary or secondary lists drupal 6 drupal 6 print menu load and output a menu

You can find out your menu name by going to admin/build/menu and hovering over it-- the name is a text string, separating the words in the menu title with dashes, and all lower case.

In your template.php

<?php
function agarictheme_preprocess_page(&$vars) {
 
$menu = menu_navigation_links("menu-name-here");
 
$vars['special_menu_name'] = theme('links', $menu);
}
?>

In page.tpl.php (or page-front.tpl.php or other variation)

<?php
 
print $special_menu_name;
?>

Note: this isn't working for us, when it should, and does when the menu code in the page template and printing directly is working.

This is what is working:

<?php
  $menu
= menu_navigation_links("menu-name-here");
  print
theme('links', $menu);
?>

Other new page variables are being passed successfully, so this is very weird.

Wait, do template variables need to be registered?

References

http://nicklewis.org/drupal-hackers-cookbook/menus/menu-navigation-links
http://api.drupal.org/api/function/theme_navigation_links/6
http://api.drupal.org/api/function/theme_menu_tree/6 (used to use this in Drupal 5, and the function is still there in Drupal 6, but it wants a menu numeric id)

Resolution

Comments

It does work

In a Zen subtheme template.php this is working:

<?php
/**
* Override or insert variables into the page templates.
*
* @param $vars
*   An array of variables to pass to the theme template.
* @param $hook
*   The name of the template being rendered ("page" in this case.)
*/
function zenjali_preprocess_page(&$vars, $hook) {
 
$menu = menu_navigation_links('menu-footer');
 
$vars['footer_links'] = theme('links', $menu);
}
?>

With the simple code below in page.tpl.php:

<?php
print $footer_links;
?>

Maybe I just forgot to flush my theme cache above!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.