Page 1 of 1

[SOLVED] IF-statement to show submenu / sidebar?

Posted: Tue Dec 07, 2010 4:00 pm
by johnkarlsson
Hey,

Not sure if this is posted right. Move it if not.

So, heres the thing. I have two sidebars.

Image

As you see, theres one called "Navigera" and one called "Just nu".


So what I want to do now is if the page contains subpages it should display "Navigera" else
it should just show the "Just now" sidebar.

Example,

Contact
 - Find us
 - Mail us

This example would show both "Navigera" and "Just nu".

And the "Home" / "Hem" would just show "Just nu".

Sorry if this is messy, here comes the code.

Code: Select all

<div id="sidebar">
			<ul>


				<li>
					<h2>Navigera</h2>
					{menu template='zionnarrows : minimal_menu'  start_level='2' collapse='1' number_of_levels='3'}
				</li>
				
				<li>
					<h2>Just nu</h2>
					<ul>
						<li>Weather and stuff,</li>

					</ul>
				</li>
			</ul>
		</div>
		<!-- end #sidebar -->

Re: IF-statement to show submenu / sidebar?

Posted: Tue Dec 07, 2010 4:09 pm
by uniqu3
In one of my templates i wanted something similar, with a difference that i wanted to disable whole sidebar, so maybe this could help you.
Install CGSimpleSmarty module.

Code: Select all

{if $cgsimple->has_children() || $cgsimple->get_parent_alias()} 
<li>
  <h2>Navigera</h2>					
  {menu template='zionnarrows : minimal_menu'  start_level='2' collapse='1' number_of_levels='3'} 				
</li>{else} 
<li>					
  <h2>Just nu</h2>					
    <ul>						
      <li>Weather and stuff,</li>					
    </ul>				
</li>{/if}
 
But if you want to hide only menu and have Just nu always visible you should simply do this:

Code: Select all

<div id="sidebar">
			<ul>


{menu template='zionnarrows : minimal_menu'  start_level='2' collapse='1' number_of_levels='3'}
	<li><h2>Just nu</h2>
					<ul>
						<li>Weather and stuff,</li>

					</ul>
				</li>
			</ul>
		</div>
The Navigera and closing should go in your MenuManager template. This way Just nu is always visible and Sublevel menu only if there are children.

Re: IF-statement to show submenu / sidebar?

Posted: Tue Dec 07, 2010 4:37 pm
by johnkarlsson
Great!

Exactly! Only one thing. I didnt really get that part with the Menu Template.
I putted everything into the Layout -> Template and now when theres children
it doesnt show the "Just nu" part.

Been working too much lately, a bit lazybrainer right now.

thanks again

Re: IF-statement to show submenu / sidebar?

Posted: Tue Dec 07, 2010 4:39 pm
by johnkarlsson
Solved it, maybe the same way you thought.

I simply put the IF-ending right after the {else}, this way Just Nu always shows. No matter what.

Thanks alot Uniqu3. Love your work (themes etc)!