Page 1 of 2
Menu manager get child elements
Posted: Tue May 11, 2010 12:14 pm
by msnijder
Hey guys!
I was wondering if I can check if the current menu item has child elements in a page. Because I would like to hide my submenu div when the parent does not have any childeren. I tried the following but didn't succeed
Code: Select all
{if $node->haschildren == true}
<div id="submenuWrap">
{menu start_level='2' number_of_levels='1'}
<div class="clearfloat"></div>
</div>
{elseif $node->haschildren == false}
<div id="submenuWrap">
this menu is empty
</div>
{/if}
Re: Menu manager get child elements
Posted: Tue May 11, 2010 12:18 pm
by vilkis
Where do you call this code: in menu template or in page template?
vilkis
Re: Menu manager get child elements
Posted: Tue May 11, 2010 12:40 pm
by msnijder
Hey there! Thanks for your repsonse. I call this code in the page template. Maybe this var isn't available in this template (when I check using 'get_template_vars', but is there a way to get it over here?
Re: Menu manager get child elements
Posted: Tue May 11, 2010 12:53 pm
by vilkis
I think you go in wrong direction. All things you can do in menu template.
vilkis
Re: Menu manager get child elements
Posted: Tue May 11, 2010 1:29 pm
by msnijder
yeah I understand that things that I want to do, I best do in the menu template, but what if I want to get it in the page template? Is it possible or not?
Re: Menu manager get child elements
Posted: Tue May 11, 2010 2:14 pm
by vilkis
It is possible but too complex and I can not see the reason to do it in this way.
vilkis
Re: Menu manager get child elements
Posted: Tue May 11, 2010 2:46 pm
by klenkes
msnijder wrote:
Hey guys!
I was wondering if I can check if the current menu item has child elements in a page. Because I would like to hide my submenu div when the parent does not have any childeren. I tried the following but didn't succeed
It may not be very elegant but you can always do it like this:
In the page template:
Code: Select all
{menu template='minimal_menu.tpl' start_level="2" assign=submenu}
{if $submenu}
<div id="some-id">
{$submenu}
</div>
{/if}
First the menu is called and its output assigned to the variable $submenu.
If the variable is filled with something(the children) it is shown. Otherwise not.
Of course my example only works if the children are in level=2.
Or take a look at the module "CGSimpleSmarty"
http://dev.cmsmadesimple.org/projects/cgsimplesmarty
It may be the better way.
--
Bernd
Re: Menu manager get child elements
Posted: Tue May 11, 2010 6:54 pm
by Dr.CSS
If you are trying to hide it, the div around it when it's empty, just put the containing div in the menu template and call your menu in the normal way with start_level='2' collapse='1' and if the top level menu 'active' item has children they will show if not there will be nothing there, in the page...
[Solved] Re: Menu manager get child elements
Posted: Wed May 12, 2010 12:09 pm
by msnijder
Hey guys! Thank you all for the help

First it was planning to hide the div of the submenu, but did that using the menu-template. Now I was just curious how to get variables from the menu temp in the page temp
Thanks
*LOCK*
Re: Menu manager get child elements
Posted: Mon May 17, 2010 6:41 pm
by Rolf
*UNLOCK*
If a topic is solved you better not lock it...
Perhaps somebody else has a related question later, and want to ask it in here...
Grtz. Rolf

Re: Menu manager get child elements
Posted: Fri Jul 16, 2010 3:26 pm
by simon.romin
Hi,
I have a similar problem.
I have three different divs for three different levels of navigation.
The problem is this: if the page has no children (i.e. a basic Contact page), I have two empty navigation divs.
Can I set the menu manager to hide any sub navigation divs if the page has no children?
Looking forward to any replies!
Thanks,
Romano
Re: Menu manager get child elements
Posted: Fri Jul 16, 2010 4:02 pm
by Dr.CSS
No, but if you put the div/s in the menu template they won't show unless the menu shows...
Re: Menu manager get child elements
Posted: Fri Jul 16, 2010 4:09 pm
by simon.romin
Thanks for the reply.
Any idea how I put the divs in the menu template?
Or are there any tutorials for this?
I'm having some trouble making sense of my menu manager!
Thanks,
Romano
Re: Menu manager get child elements
Posted: Fri Jul 16, 2010 4:11 pm
by Dr.CSS
Copy the menu you use then at the top above the put your div, at the bottom after the for each etc. put your some of them already have a div called menuwrapper...
Re: Menu manager get child elements
Posted: Fri Jul 16, 2010 4:56 pm
by simon.romin
Sorry, I don't understand your explanation Dr.CSS.
Do you know if there is any documentation or tutorials for this?
I have attached a screenshot to illustrate my problem.
I am currently on a page that has no children, but there are still empty blocks on the page.
Thanks,
Romano