CMS Made Simple Forums
https://forum.cmsmadesimple.org/

(solved) Dynamically show/hide submenu
https://forum.cmsmadesimple.org/viewtopic.php?f=20&t=23054
Page 1 of 1

Author:  lprintz [ Thu Jun 19, 2008 8:51 pm ]
Post subject:  (solved) Dynamically show/hide submenu

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


Author:  Dr.CSS [ Fri Jun 20, 2008 12:43 am ]
Post subject:  Re: Dynamically show/hide submenu

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?...

Author:  lprintz [ Fri Jun 20, 2008 12:30 pm ]
Post subject:  Re: Dynamically show/hide submenu

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

Author:  lprintz [ Fri Jun 20, 2008 12:42 pm ]
Post subject:  Re: Dynamically show/hide submenu

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

Author:  Dr.CSS [ Fri Jun 20, 2008 5:15 pm ]
Post subject:  Re: Dynamically show/hide submenu

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}

Author:  lprintz [ Fri Jun 20, 2008 5:22 pm ]
Post subject:  Re: Dynamically show/hide submenu

Thanks so much...I'll give it a shot!

Len

Author:  lprintz [ Fri Jun 20, 2008 6:00 pm ]
Post subject:  Re: Dynamically show/hide submenu

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:



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?

Author:  Dr.CSS [ Fri Jun 20, 2008 6:16 pm ]
Post subject:  Re: Dynamically show/hide submenu

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...

Author:  lprintz [ Fri Jun 20, 2008 6:28 pm ]
Post subject:  Re: Dynamically show/hide submenu

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

Author:  Dr.CSS [ Fri Jun 20, 2008 6:58 pm ]
Post subject:  Re: Dynamically show/hide submenu

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...

Author:  Zoorlat [ Fri Jun 20, 2008 7:39 pm ]
Post subject:  Re: Dynamically show/hide submenu

Len,

Try this in your template:
Code:
{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

Author:  lprintz [ Fri Jun 20, 2008 7:57 pm ]
Post subject:  Re: Dynamically show/hide submenu

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

Author:  requish [ Fri Apr 30, 2010 7:37 pm ]
Post subject:  Re: Dynamically show/hide submenu

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:
{if $has_children and $current}<h1>project list</h1>{menu start_level="2"}  {else}{/if}

please help.  ::)

Author:  nervino [ Wed Sep 22, 2010 4:13 pm ]
Post subject:  Re: (solved) Dynamically show/hide submenu

..a little bit late..
However:

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

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/