Page 1 of 1

(solved) Dynamically show/hide submenu

Posted: Thu Jun 19, 2008 8:51 pm
by lprintz
Hello all!

I've successfully implemented CMSMS on my new site...thanks to a couple of postings :)

I'm hoping somebody can help me with one last piece...

I'd like to have the submenu block only appear IF there are pages under the parent. I can always create a template for each section but this obviously would be very clunky and not dynamic.

As an example, please view one of my site sections - http://executivedesigns.com/orange-prot ... =project-2

This works great, however, if there weren't any projects in this area, I would want the submenu in the lower right - along with it's header - to NOT appear.

I've included the code for this block below if it helps.

Any ideas would be most appreciated...thank you!

Len



project list
   
   
   {menu start_level="2"} 
   


Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 12:43 am
by Dr.CSS
Seems to work or are you using 2 diff. templates?...

You can make a second content block and add h1 and menu call in it...

Why mix table and div?.. if you don't mind my asking?...

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 12:30 pm
by lprintz
Thanks Mark!

Right now I am using 2 templates...the home page doesn't show the submenu as I've hid the code...I'd love for this to by dynamic though so this block will appear if there are pages under the home parent.

I know about the table :(  This was to be my first, fully W3C compliant, tableless site but I needed to get the top navigation vertically centered. I found fixes and hacks that worked in IE but, unfortunately, it didn't work in Firefox. I finally gave up :)

Len

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 12:42 pm
by lprintz
One other thing...I figured what you meant by it 'working'

The menu does appear only if there are subpages HOWEVER I'd like a unique and dynamic header for the menu. This can simply be pulled from the page alias. Can this be built into the menu function?

Thanks again!

Len

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 5:15 pm
by Dr.CSS
Yes you have to make a new menu template and use some smarty in it, you have to install CGSimpleSmarty so the smarty calls in menu template work, it has no admin I looked after install and thought something was wrong  ;)

Here is a site using it...

http://touareg.websitewelcome.com/~milesfin/  then go to about us, services is not a menu but anchor links even tho it goes no where...

Top of menu template, if no children then no menu, you can put a {content block="new block"} below where the menu tag goes so if page has no menu/children you can put something there so it's not empty, this block was used to insert the image on her bio page under about us...

is used to make the root page alias show as a link to keep the style consistant...

{if $count > 0}

{$cgsimple->get_root_alias('','root_alias')}{$cgsimple->get_page_title($root_alias)}
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string="" times=$node->depth-$node->prevdepth}

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 5:22 pm
by lprintz
Thanks so much...I'll give it a shot!

Len

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 6:00 pm
by lprintz
hmmm...still having issues...I know I'm close!

I installed the smarty module and here's my code for the submenu on the right:


   
{$cgsimple->has_children('',$has_children)}{if $has_children}project list{menu start_level="2"}  {else}{/if}



I expected it to look like this page if there are 'children' - http://executivedesigns.com/orange-prot ... /project-1

But I get this - http://executivedesigns.com/orange-prot ... p/projects

Any thoughts?

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 6:16 pm
by Dr.CSS
Well I don't know about putting it in your template, since I used it in a "menu template" but you have {else}{/if} which I'm surprised didn't throw a smarty error, I would think you would need an opening {if} has children then the {else}{/if}...

But like I showed in the post it was pulling the root page alias bla bla bla...

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 6:28 pm
by lprintz
here's the method to my madness

I thought the logic below was 'if the page has children' then display menu or 'else' don't display anything.

{if $has_children}project list{menu start_level="2"}  {else}{/if}

If this should not be in the template, please explain where best to place this code.

Thanks again for your assistance. If I can't solve this it isn't a show-stopper, I'd just like to make this as easy as possible for my client to maintain.

Len

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 6:58 pm
by Dr.CSS
I believe the {if $has_children} only works in the menu engine not the template, $has_children is part of the menu parameters so, iirc, it's the only one that knows what that means...

OK what I would do is make a new menu template, a copy of simple_navigation since it's what gets called when no template is called, and add the project list above the and have a content block on the side and call the menu in it on the parent/Projects page...

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 7:39 pm
by Zoorlat
Len,

Try this in your template:

Code: Select all

{if $cgsimple->has_children()}<h1>project list</h1>{menu start_level="2"}{/if}
You do not need the else-statement, unless you want to print some "this page has no children"-text.
You can also use smarty to get the h1-text according to the parent you are using.

Cheers!
Z

Re: Dynamically show/hide submenu

Posted: Fri Jun 20, 2008 7:57 pm
by lprintz
Thanks Zoorlat and Mark!

I solved the issue and I was making it much more complicated than it needed to be.

I simply copied the simple menu template and changed the header (thanks Mark!)...didn't need the those conditional smarty statements at all.

Now to tackle the search module :)

Len

Re: Dynamically show/hide submenu

Posted: Fri Apr 30, 2010 7:37 pm
by requish
lprintz wrote: here's the method to my madness

I thought the logic below was 'if the page has children' then display menu or 'else' don't display anything.

{if $has_children}project list{menu start_level="2"}  {else}{/if}

If this should not be in the template, please explain where best to place this code.

Thanks again for your assistance. If I can't solve this it isn't a show-stopper, I'd just like to make this as easy as possible for my client to maintain.

Len
Hi, tell me.. how to do to be has_children and current_page? Some like this doesnt work:

Code: Select all

{if $has_children and $current}<h1>project list</h1>{menu start_level="2"}  {else}{/if}
please help.  ::)

Re: (solved) Dynamically show/hide submenu

Posted: Wed Sep 22, 2010 4:13 pm
by nervino
..a little bit late..
However:

Code: Select all

{$cgsimple->get_root_alias('','root_alias')}
{if ($cgsimple->has_children()) || ($cgsimple->has_children($root_alias))}
{$cgsimple->get_page_title($root_alias)}
{/if}