Pregunta:
Estoy tratando de imprimir los enlaces secundarios para el menú principal expandidos en mi nodo de plantilla – products.tpl.php. En mi menú tengo tres niveles.
-Productos
–Categoria de producto
—Producto
-Otro enlace de menú
El resultado debería ser un menú con todas las categorías de productos con los elementos secundarios. No quiero imprimir el nivel raíz en el menú; Solo quiero que aparezca el nivel secundario y sus hijos.
Intenté imprimir el menú secundario de esta manera, pero los elementos secundarios no aparecen. Se agradece cualquier ayuda.
$secondary_menu = theme_get_setting('toggle_secondary_menu') ? menu_secondary_menu() : array();
print theme('links__system_main_menu', array(
'links' => $secondary_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
Respuesta:
En su plantilla de temas.php agregue lo siguiente:
function THEMENAME_preprocess_page(&$variables) {
// Get the entire menu tree (you can replace this string with any menu you want)
$main_menu_tree = menu_tree_all_data('main-menu');
// Generate structure for rendering the menu.
$menu = menu_tree_output($tree);
// Replace the $menu array with the #below array beloning to the first top
// level menu item.
$menu = $menu[key($menu)]['#below'];
// Add $main_menu_no_top as a variable to use in our theme
$variables['main_menu_no_top'] = $menu;
}
Luego, en page.tpl.php, puede usar:
<?php print render($main_menu_no_top); ?>