Is someone willing to give this some love and write a doc page at How To Do Theming Examples Made Simple in Drupal 7

See these forum topics for background:
Displaying my custom menu?
How to print a menu in Drupal 7?

If I'll figure it out I'll post it in the documentation, but I've spend 5 hours on this already, unfortunately there is a limit on how much time I can spend on this, and can't seem to figure it out.

Comments

Anonymous’s picture

Issue summary: View changes

Text revision

Anonymous’s picture

Title: Displaying my custom menu? » How to display a menu in a template file?
Anonymous’s picture

Issue summary: View changes

Text revision

Anonymous’s picture

Issue summary: View changes

Text revision

Anonymous’s picture

Issue summary: View changes

Text revision

Anonymous’s picture

Further research on this subject has led to some answers, however some things remain left to solve.

The following code gives an expected result. It also does not result in error messages during testing. However in totality needs peer review.

In template.php:

<?php

function THEMENAME_menu_tree__your_menu_name($variables){
  return '<ul class="your-custom-class" id="your-custom-id">' . $variables['tree'] . '</ul>';
}

function THEMENAME_menu_link__your_menu_name($variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

?>

See:
http://drupal.stackexchange.com/questions/7274/how-to-theme-a-menu-block

Please note: It is unknown whether the 'THEMENAME' is case sensitive. I used normal letters (not capitalized), and it worked fine. It may be good to note that my theme name is a single word. It is unknown at this time if the words a theme name with multiple words need to be seperated by an underscore(_) or a dash(-).

Then in page.tpl.php where you want the menu to show:

<?php 

print drupal_render(menu_tree_output(menu_tree_all_data('your-menu-name')));

?>

This would be in line with Drupal practice for Drupal 7 as far as I can determine at this time.

To Do

1. How to add the title of a menu?

Doing a var_dump gives an insight on to where the value is stored, but I haven't been able to find any info on how to add this in the template.php:


var_dump(menu_tree_all_data('your-menu-name'));
var_dump(menu_tree_output(menu_tree_all_data('your-menu-name')));

2. Performance/ caching pros and cons versus other options such as using a block to show a menu in a template file.

3. Make a user friendly write-up that even nanna could understand, and add this to doc page.

Anonymous’s picture

For those interested there is a group discussion with suggestions and tips as well here.

dddave’s picture

Status: Active » Closed (fixed)
dddave’s picture

Issue summary: View changes

Text revision