By Fluffy Convict on
I have created a few nodes and made reference to a hierarchical "main menu":
Home
---About
------Team
------Contact
---Products
------Fruit
------Meat
When I add the "main menu" block to the sidebar (on admin/structure/block), this menu appears as it should. However, if I put print_r($main_menu); in my page.tpl.php file, it returns an empty array!
This is driving me nuts. Why is the $main_menu array empty?
B.T.W. It's not a caching problem: I have cleared all caches. Besides, everything else is working fine...aarrgh!!
Comments
I had to use this in my
I had to use this in my templates preprocess_page to get $main_menu to work
function template_preprocess_page(&$vars) {
$vars['main_menu'] = menu_main_menu();
}
This didn't work for me in
This didn't work for me in Drupal 7.
It is working well for me.
It is working well for me. Drupal 7.
theme_links
you need to run this through theme_links, as in:
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
It's driving me crazy. What
It's driving me crazy. What do I need to overwrite in template.php to remove the ul and li tags?
_menu_link
_menu_local_task
Can anyone provide an example to output a menu like this:
Home | Item1 | Item2
Or just the method to overwrite would be helpful too...
The code that @Jeff wrote
The code that @Jeff wrote will do this. You should be putting a menu in a
<ul><li>format.Just use CSS to put a border right as the inline class is already included in the array.
so something like:
Did you find a solution to
Did you find a solution to this? I've tried theme_links, theme_menu_tree and theme_menu_link and none of them are working.
theme_links is the one, lord
theme_links is the one, lord knows why you are trying to use theme_menu_tree or theme_menu_link, they are totally different things altogether.
Look at Stark, Bartik, Adaptivetheme, Zen etc etc all these themes use theme_links one way or another.
If its not working for you, examine YOUR code.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
It's a feature...
The variables 'main-menu' and 'secondary-menu' appear to always be defined (please correct me if my testing is wrong); however, they will only be populated with data when two things happen:
This solved my problem. I had
This solved my problem. I had no idea this would affect me at all..
I still have the same problem
Code for my page.tpl.php
if ($main_menu):endif;Main menu has links Menu Item1 and Menu Item 2. here are no feature overrides in the .info file. $main_menu is always empty and if you switch the theme to bartik it has the same problem.
however if you add the main menu to rightside bar it displays there but mine $main_menu is empty :(
Spent days on this I might just hard code the menu as its cost too much time. :(
I ended up solving this issue
I ended up solving this issue by calling menu_tree and using the render function to output the html.
Yes, I also solved the
Yes, I also solved the problem for main-menu using below code in page.tpl.php:-
$pid = variable_get('menu_main_links_source', 'main-menu');
$tree = drupal_render(menu_tree($pid));
print $tree;
You can also change your class of the menu.
Thanks