Menu manager get child elements

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
msnijder
Forum Members
Forum Members
Posts: 16
Joined: Sun May 09, 2010 3:36 pm

Menu manager get child elements

Post 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}
vilkis

Re: Menu manager get child elements

Post by vilkis »

Where do you call this code: in menu template or in page template?

vilkis
msnijder
Forum Members
Forum Members
Posts: 16
Joined: Sun May 09, 2010 3:36 pm

Re: Menu manager get child elements

Post 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?
vilkis

Re: Menu manager get child elements

Post by vilkis »

I think you go in wrong direction. All things you can do in menu template.

vilkis
msnijder
Forum Members
Forum Members
Posts: 16
Joined: Sun May 09, 2010 3:36 pm

Re: Menu manager get child elements

Post 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?
vilkis

Re: Menu manager get child elements

Post by vilkis »

It is possible but too complex and I can not see the reason to do it in this way.

vilkis
klenkes
Power Poster
Power Poster
Posts: 307
Joined: Mon Sep 08, 2008 9:43 am

Re: Menu manager get child elements

Post 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
Last edited by klenkes on Tue May 11, 2010 6:36 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Menu manager get child elements

Post 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...
msnijder
Forum Members
Forum Members
Posts: 16
Joined: Sun May 09, 2010 3:36 pm

[Solved] Re: Menu manager get child elements

Post 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*
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Menu manager get child elements

Post by Rolf »

*UNLOCK*  :D

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  :)
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
simon.romin
Forum Members
Forum Members
Posts: 65
Joined: Tue Jul 13, 2010 9:31 am

Re: Menu manager get child elements

Post 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
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Menu manager get child elements

Post by Dr.CSS »

No, but if you put the div/s in the menu template they won't show unless the menu shows...
simon.romin
Forum Members
Forum Members
Posts: 65
Joined: Tue Jul 13, 2010 9:31 am

Re: Menu manager get child elements

Post 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
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Menu manager get child elements

Post 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...
simon.romin
Forum Members
Forum Members
Posts: 65
Joined: Tue Jul 13, 2010 9:31 am

Re: Menu manager get child elements

Post 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
Attachments
CMSMS_template_layout.JPG
Post Reply

Return to “CMSMS Core”