The default $main_menu
variable in page.tpl.php
is set to menu_main_menu()
, which is a contextual view of the main menu tree.
To get your desired output, you need to get the entire menu tree using menu_tree_all_data()
and menu_tree_output()
.
To do this in your theme, create template.php
if you haven't already, and add a new preprocess function for the page template:
function THEMENAME_preprocess_page(&$variables) {
// Get the entire main menu tree
$main_menu_tree = menu_tree_all_data('main-menu');
// Add the rendered output to the $main_menu_expanded variable
$variables['main_menu_expanded'] = menu_tree_output($main_menu_tree);
}
Then, in page.tpl.php
, you can just use:
<?php print render($main_menu_expanded); ?>
to get a expanded, nested unordered list of the main menu.
For a little more flexibility, you might want to consider the Menu Block module, which will let you create blocks of expanded menus out of the box with its Expand all children of this tree option as well as a host of other options for segmenting menu trees.