Page 1 of 1
[SOLVED] Conditional menu (one level replacing another)
Posted: Mon Apr 21, 2008 1:41 pm
by webform
Is it possible to load different menus depending of what level the previous selected menu item was?
I recived a layout from a client with room for one level in the menu (he don't want dropdowns or any other area with menues). So the question that haunts me, is it possible to have some kind of test if there is any children to a menu item, and if so replace the 1. level menu with next level menu if that item is selected?
I hope my question make any sense?
Re: Conditional menu (one level replacing another)
Posted: Mon Apr 21, 2008 10:16 pm
by Richardo P
Have you read this tutorial:
3 menus with menu manager:
http://themes.cmsmadesimple.org/menu_manager_options.html
Richard
Re: Conditional menu (one level replacing another)
Posted: Tue Apr 22, 2008 6:04 am
by webform
Yes i've read your tuturial, but it doesn't look like that is what i'm looking for.
My problem is i need several menues using the same space on the page only showing depending on the selection/level in the previous menu - something like this:
Code: Select all
{If level == 2}
{menu number_of_levels="1" start_level='2'}
{Elseif level == 3}
{menu number_of_levels="1" start_level='3'}
{Else}
{menu number_of_levels="1"}
{/If}
I can't have dropdowns or other ways (three structure) to display other levels in the menu because i have to follow a rigid design

- otherwise it would be easy!
Re: Conditional menu (one level replacing another)
Posted: Tue Apr 22, 2008 11:41 am
by Richardo P
you can use the page alias to determine which page you are on, then display a different menu call dependant on that page.
Do a search through the forum as i've already answered this, but it can be something like:
{if $pagealias == 'x'}
{menu options}
{elseif $pagealias == 'y'
{menu different options}
{/if}
theres plenty of stff on this forum that should help. Also have a look at the smarty manual. Also have a look at the help page for the module cgsimplesmarty
Richard
Re: Conditional menu (one level replacing another)
Posted: Tue Apr 22, 2008 10:37 pm
by webform
Thanks for reply! It start to look like something!
Only problem, as i see it, is the lack of page dynamic in this setup as i have to know the name of the page alias beforehand, and on this site where will be a constant flow of subpages coming and going
I'll give it at try and see where it leeds me - maybe i can even persuade the designer to rethink the menu structure

Re: Conditional menu (one level replacing another)
Posted: Tue Apr 22, 2008 10:39 pm
by calguy1000
Look at the CGSimpleSmarty module, it has methods for get_root_alias and get_parent_alias
Re: Conditional menu (one level replacing another)
Posted: Tue Apr 22, 2008 11:52 pm
by Dr.CSS
calguy1000 wrote:
Look at the CGSimpleSmarty module, it has methods for get_root_alias and get_parent_alias
I've used these lately and they are great tools to know...
Re: Conditional menu (one level replacing another)
Posted: Mon May 05, 2008 6:15 pm
by tg20
I am trying to use CGSimpleSmarty to do the same thing as "webform" is trying to do, but I can't seem to figure out how to code it. I've been playing with it, but more times that not I get a code error. I would love to hear how you think I should do this.
-Tg20
Re: Conditional menu (one level replacing another)
Posted: Tue May 06, 2008 7:29 pm
by webform
I ending up paying a hardcore PHP coder to get it to work as i knew he had a firm grasp on smarty and PHP. I've included the 2 menu templates and the navigation section of my page template in this post you can take a look at and see if you can use it for your need!
Comments:
Some things you should be aware of; Some CSS ID's are called in both templates and that is wrong! They should have unique ID pr. template and in the stylesheet (I haven't corrected it yet).
And as the client wants two languages on the site, the templates use sectionheader to divide the languages - You should be able to omit the test for the section in the page template {if substr($friendly_position, 0, 3) == '10.'} but play around with it and see if it works for you!
Head menu template:
Code: Select all
{if $count > 0}
<ul>
{foreach from=$nodelist item=node name=items}
{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}</li>
{elseif $node->index > 0}</li>
{/if}
{if $node->current == true}
<li{if $smarty.foreach.items.last} class="last"{/if}><a href="{$node->url}" {if $node->target ne ""} target="{$node->target}"{/if}id="current" name="current">{$node->menutext}</a>
{elseif $node->parent == true}
<li{if $smarty.foreach.items.last} class="last"{/if}><a href="{$node->url}" {if $node->target ne ""} target="{$node->target}"{/if}id="currentAncestor">{$node->menutext}</a>
{elseif $smarty.foreach.items.last}
<li class="last"><a href="{$node->url}" {if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
{elseif $node->type == 'sectionheader'}
<li class="sectionheader">{$node->menutext}
{elseif $node->type == 'separator'}
<li class="separator" style="list-style-type: none;"> <hr />
{else}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
{/if}
{/foreach}
{repeat string="</li></ul>" times=$node->depth-2}</li>
</ul>
{/if}
Submenu template:
Code: Select all
{if $count > 0}
<ul>
{foreach from=$nodelist item=node name=items}
{if $node->current == true}
{if $smarty.foreach.items.total == 1}
<li{if $smarty.foreach.items.last} class="last"{/if}><a href="{$node->url}" {if $node->target ne ""} target="{$node->target}"{/if}id="current" name="current">{$node->menutext}</a>
{/if}
{elseif $node->parent == true}
<li{if $smarty.foreach.items.last} class="last"{/if}><a href="{$node->url}" {if $node->target ne ""} target="{$node->target}"{/if}id="currentAncestor">{$node->menutext}</a>
{elseif $smarty.foreach.items.last}
<li class="last"><a href="{$node->url}" {if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
{elseif $node->type == 'sectionheader'}
<li class="sectionheader">{$node->menutext}
{elseif $node->type == 'separator'}
<li class="separator" style="list-style-type: none;"> <hr />
{else}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
{/if}
{/foreach}
</ul>
{/if}
In the page template the menus is called:
Code: Select all
<!-- start navigation -->
<div id="navcontainer">
{if substr($friendly_position, 0, 3) == '10.'}
{menu template='momentum_menu' start_element='10.1' show_root_siblings=1 number_of_levels='1'}
{else}
{menu template='momentum_menu' collapse='1' number_of_levels='1'}
{/if}
</div>
<div id="submenu">
{if $smarty.request.page != ''}
{menu template='momentum_submenu' start_page=$smarty.request.page collapse="1"}
{/if}
</div>
<!-- end navigation -->
Re: [SOLVED] Conditional menu (one level replacing another)
Posted: Thu May 08, 2008 6:11 pm
by tg20
Is there a way that I could make this display a list of all the pages on the same level as the page your currently on, instead of showing the pages beneath it?
For instance...
Say I have this set up
1.0
- 1.1
- 1.2
- 1.3
- - 1.31
- - 1.32
- - 1.33
2.0
3.0
4.0
If I was on page 1.0, the sub navigation would read:
1.0
2.0
3.0
4.0
instead of showing:
1.1
1.2
1.3
And the same would happen as you navigate down the page.
Is this possible? The reason I want to do this is because as I navigate downward, the content of some pages already include a list of the pages beneath it. But I also want a quick way for visitors to jump through pages on the same level.
I have tried different ways to subtract one (1) from the $smarty.request.page value, but so far have had no success.