Page 1 of 1

Menus: add a class to FIRST menu item

Posted: Wed Oct 31, 2007 8:23 pm
by kermit
example:


Menu One
Menu Two
...


Right now, I've hacked up a menu (below, originally minimal_template.tpl as on this install all menus are only 1 level) using {counter}..

...but there's gotta be an easier way.

Code: Select all

{* CSS classes used in this template:
.currentpage - The active/current page
.bullet_sectionheader - To style section header
hr.separator - To style the ruler for the separator *} 
{if $count > 0}
<div class="sidebox">
<h1>This Section</h1>
{counter assign="countitems" start=0}
<ul class="sidemenu">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{counter assign="countitems" start=0}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{counter assign="countitems" start=0}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}
{if $node->current == true}{counter assign="countitems"}
<li><a href="{$node->url}" {if $countitems == 1}class="currentpage top"{else}class="currentpage"{/if}{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->parent == true && $node->depth == 1}{counter assign="countitems"}
<li class="activeparent"> <a href="{$node->url}" {if $countitems == 1}class="activeparent top"{else}class="activeparent"}{/if}{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->type == 'sectionheader'}{counter assign="countitems"}
<li class="sectionheader">{$node->menutext}

{elseif $node->type == 'separator'}{counter assign="countitems"}
<li style="list-style-type: none;"> <hr class="separator" />

{else}{counter assign="countitems"}
<li><a {if $countitems == 1}class="top" {/if}href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{/if}

{/foreach}

{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
</div>
then, the same question could be asked about the very LAST item as well..

Re: Menus: add a class to FIRST menu item

Posted: Thu Nov 01, 2007 5:37 pm
by bterkuile