Page 1 of 1

[SOLVED] Setting last class AND current item in Menu Manager

Posted: Sat Apr 12, 2008 1:07 pm
by webform
I've tried to set a "last class" in Menu Manager so i can remove some graphic on the last menu item and it's almost working perfectly. The only problem i have, is if the menu item is the current AND last it still shows the graphic. Isn't there some way to tell menu manager that something is both .last class and current?

My code: 

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><a href="{$node->url}" {if $node->target ne ""} 
target="{$node->target}"{/if}id="current" name="current">{$node->menutext}</a>

{elseif $node->parent == true}
<li><a href="{$node->url}" {if $node->target ne ""} 
target="{$node->target}"{/if}id="currentAncestor" name="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}
I've tried to write this condition but something is wrong with it - looks like it won't accept the AND operator or i'm just plain wrong:

Code: Select all

{elseif  $smarty.foreach.items.last and $node->current == true}
<li class="last"><a href="{$node->url}" {if $node->target ne ""}
target="{$node->target}"{/if}id="current" name="current">{$node->menutext}</a>

Re: [SOLVED] Setting last class AND current item in Menu Manager

Posted: Mon Apr 14, 2008 8:59 am
by webform
OK i got a solution that is working  ;D

It was wrong to try to write an AND condition - instead i wrote:

Code: Select all

{if $node->current == true}
<li{if $smarty.foreach.items.last} class="last"{else}{/if}><a href="{$node->url}" {if $node->target ne ""} 
target="{$node->target}"{/if}id="current" name="current">{$node->menutext}</a>
Much more simpel and saves some code lines.

Re: [SOLVED] Setting last class AND current item in Menu Manager

Posted: Mon Apr 14, 2008 5:18 pm
by Pierre M.
Hello,

thank you for sharing this. Usefull, well done. Feel free to wiki it.

Or if you know git, see this yesterday's blog post about github : you could contribute your patch to some of the sample templates and content for 2.0.

Pierre M.