2

I'm trying to output the main_menu in to a custom theme on the page.tpl.php template however nothing is displaying when I add <?php print theme("links", $main_menu) ?>

However when I do a var_dump on the $main_menu I get

array(2) { ["menu-218"]=> array(2) { ["href"]=> string(7) "" ["title"]=> string(4) "Home" } ["menu-335"]=> array(2) { ["href"]=> string(6) "node/1" ["title"]=> string(4) "Home" } }

What might I be doing wrong? I'm new to Drupal so be kind please :D

I do have features[] = main_menu in my .info file.

3

Try adding the following lines to your template file. Works for me.

$main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
print drupal_render($main_menu_tree);
  • Still no result unfortunately, do I need to put this in a function in the template file? – PapaSmurf Oct 30 '12 at 12:13
  • yes, in your theme's page.tpl.php, wherever you need to print (generally inside <div id='header-menu><?php //copy above code here ?> </div>. Make sure you clear your cache after this. – AjitS Oct 30 '12 at 12:16
  • Sorry I miss understood you when you said template file, I thought the template.php file :P Thats worked great thanks! How do I add custom attributes to this though so I may style it? – PapaSmurf Oct 30 '12 at 12:19
  • There is a id to the div already; you can add a class as well by something like <div id='header-menu' class='header-menu-class'>.... – AjitS Oct 30 '12 at 12:22
  • 2
    You're welcome :) Drupal community will always welcome you :) happy learning! – AjitS Oct 30 '12 at 12:35

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.