I'm trying to show the Main menu in two places, once as a dropdown menu at the top, then again in the footer as a fully expanded (non-collapsible) set of links. I'm using the Superfish module to handle the top menu, and Menu Blocks to place the menu in my footer region. I'm using D7 and am sub-themeing the Bootstrap theme. Ideally, I'm looking for a way to simply output the Main menu as a very simple unordered list of links, without any of the dropdown classes or scripting applied to it. Where would be the best place to do this? I tried overriding theme_menu_link
but that didn't seem right (since I can't figure out how to get the region.)
-
[How to print a custom menu in Drupal 7?][1] - replace menu-site-menu to main-menu [1]: stackoverflow.com/questions/4824093/…– NikitCommented May 6, 2014 at 21:34
-
Thanks for the link! So there is no way to do this without editing the template? (I don't have a problem with this, just curious.)– ken.dunningtonCommented May 7, 2014 at 19:11
-
Unfortunately, that only gives one level of the menu, I need all the submenu items as well.– ken.dunningtonCommented May 7, 2014 at 19:23
2 Answers
We use the menu_block module for this - it lets you create unlimited menu blocks and control menu depth and other options.
This module provides configurable blocks of menu links with advanced features not available in Drupal 8 core.
Drupal 8 core allows you to display blocks of menu links starting with any desired level of a menu and limited to any desired depth.
And this Menu Block module provides additional configuration so you can choose to expand all menu links with children or to root the menu tree to a specific menu item.
The Drupal 7 version of this module provides all of these features since Drupal 7 core does not have any of this functionality.
So I just noticed you're already using menu_block. You can add multiple_menu blocks - you should simply be able to add a new menu_block for the main-menu on your site and use that one in the footer.
This is the solution I ended up using. It works, but I'm not confident it's the "right" way to do it. The menu will never be more than 2 levels deep, so it's not a recursive solution by design. This is in my page.tpl.php
right above print render($page['footer']);
$tree = menu_build_tree('main-menu');
$output = "<ul>";
foreach ($tree as $item) {
$menu_link = $item['link'];
$link = sprintf('<a href="%s" title="%s">%s</a>', $menu_link['link_path'], $menu_link['link_title'], $menu_link['link_title']);
$element = "<li>".$link;
if (isset($item['below']) && count($item['below'])) {
$element .= "<ul>";
foreach ($item['below'] as $sub_item) {
$sub_menu_link = $sub_item['link'];
$sub_link = sprintf('<a href="%s" title="%s">%s</a>', $sub_menu_link['link_path'], $sub_menu_link['link_title'], $sub_menu_link['link_title']);
$sub_element = "<li>".$sub_link."</li>";
$element .= $sub_element;
}
$element .= "</ul>";
}
$element .= "</li>";
$output .= $element;
}
output .= "</ul>";
print $output;