Page 1 of 1
How to get the last item in the menu
Posted: Thu Jul 16, 2009 8:06 am
by blue_francis14
Hello,
I am currently using CMSMS 1.5.1 and I am trying to achieve this navigation
Home | About Us | Contact
Unfortunately, it's always displaying an extra pipe at the end
Home | About Us | Contact |
Is there a way to do this? Like {$node->last_item}?
Thanks in advance!
Re: How to get the last item in the menu
Posted: Thu Jul 16, 2009 1:42 pm
by calguy1000
Read the smarty manual.
Re: How to get the last item in the menu
Posted: Thu Jul 16, 2009 2:31 pm
by Jeff
How about just searching the forum. I have seen this request posted and answer multiple times within the last couple days.
Re: How to get the last item in the menu
Posted: Fri Jul 17, 2009 4:20 am
by blue_francis14
I am not really sure what keyword to use to search this. The admin could put it in as a sticky if you have seen it asked a couple of times.
Re: How to get the last item in the menu
Posted: Fri Jul 17, 2009 5:00 am
by blue_francis14
I read the smarty manual and got it to work. Here is the code
Code: Select all
{* CSS classes used in this template:
#menuwrapper - The id for the <div> that the menu is wrapped in. Sets the width, background etc. for the menu.
#primary-nav - The id for the <ul>
.menuparent - The class for each <li> that has children.
.menuactive - The class for each <li> that is active or is a parent (on any level) of a child that is active. *}
{if $count > 0}
<div id="menuwrapper">
<ul id="primary-nav">
{foreach from=$nodelist item=node name=foo}
{if $node->depth > $node->prevdepth}
{repeat string="<ul class='unli'>" 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->parent == true or ($node->current == true and $node->haschildren == true)}
<li class="menuactive menuparent">
<a class="menuactive menuparent" {elseif $node->current == true}
<li class="menuactive">
<a class="menuactive" {elseif $node->haschildren == true}
<li class="menuparent">
<a class="menuparent" {elseif $node->type == 'sectionheader'}
<li class="sectionheader"><span>{$node->menutext}</span> {elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="separator" />{else}
<li>
<a {/if}
{if $node->type != 'sectionheader' and $node->type != 'separator'}
href="{$node->url}"><span>{$node->menutext}</span></a>
{if $smarty.foreach.foo.last == 0} |
{/if}
{elseif $node->type == 'sectionheader'}
><span>{$node->menutext}</span></a>
{/if}
{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}
</li>
</ul>
<div class="clearb"></div>
</div>
{/if}
Do you think there could be a better solution to this?