[SOLVED] Conditional menu (one level replacing another)

General project discussion. NOT for help questions.
Post Reply
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

[SOLVED] Conditional menu (one level replacing another)

Post 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?
Last edited by webform on Tue May 06, 2008 7:29 pm, edited 1 time in total.
Richardo P
Forum Members
Forum Members
Posts: 33
Joined: Fri Aug 17, 2007 8:35 am

Re: Conditional menu (one level replacing another)

Post by Richardo P »

Have you read this tutorial:

3 menus with menu manager: http://themes.cmsmadesimple.org/menu_manager_options.html

Richard
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Conditional menu (one level replacing another)

Post 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!
Richardo P
Forum Members
Forum Members
Posts: 33
Joined: Fri Aug 17, 2007 8:35 am

Re: Conditional menu (one level replacing another)

Post 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
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Conditional menu (one level replacing another)

Post 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  ;)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Conditional menu (one level replacing another)

Post by calguy1000 »

Look at the CGSimpleSmarty module, it has methods for get_root_alias and get_parent_alias
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Conditional menu (one level replacing another)

Post 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...
tg20
New Member
New Member
Posts: 4
Joined: Thu Jun 14, 2007 7:42 am

Re: Conditional menu (one level replacing another)

Post 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
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Conditional menu (one level replacing another)

Post 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 -->
tg20
New Member
New Member
Posts: 4
Joined: Thu Jun 14, 2007 7:42 am

Re: [SOLVED] Conditional menu (one level replacing another)

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

Return to “General Discussion”