(solved) Dynamically show/hide submenu

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

(solved) Dynamically show/hide submenu

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

Last edited by lprintz on Fri Jun 20, 2008 7:58 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Dynamically show/hide submenu

Post 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?...
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

Re: Dynamically show/hide submenu

Post 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
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

Re: Dynamically show/hide submenu

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

Re: Dynamically show/hide submenu

Post 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}
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

Re: Dynamically show/hide submenu

Post by lprintz »

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

Len
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

Re: Dynamically show/hide submenu

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

Re: Dynamically show/hide submenu

Post 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...
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

Re: Dynamically show/hide submenu

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

Re: Dynamically show/hide submenu

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

Re: Dynamically show/hide submenu

Post 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
lprintz
Forum Members
Forum Members
Posts: 76
Joined: Thu Jun 19, 2008 5:59 pm

Re: Dynamically show/hide submenu

Post 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
User avatar
requish
Forum Members
Forum Members
Posts: 183
Joined: Sat Jan 24, 2009 3:12 pm

Re: Dynamically show/hide submenu

Post 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.  ::)
CMS Made Simple! Best CMS! :)
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: (solved) Dynamically show/hide submenu

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

Return to “Layout and Design (CSS & HTML)”