Page 1 of 1

smarty fix to add last-child class to menu

Posted: Mon Aug 04, 2008 8:41 pm
by studip101
hi everyone. I need help customizing a menu template so that a class of "last-child" is added to each last, second-level menu item.

The HTML is structured like this:


              TOP LEVEL #1
     

TOP LEVEL #2
       
                      SECOND LEVEL ITEM #1 UNDER TOP LEVEL ITEM #2
                LAST SECOND LEVEL ITEM UNDER TOP LEVEL ITEM #2
               



The end goal is to have the red tags be generated with a class of "last-child", in addition to any other classes which the template is currently giving them.

The SMARTY template which is generating the menu is below:

{if $count > 0}


{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}

{repeat string="" times=$node->depth-$node->prevdepth}
{elseif $node->depth prevdepth}

{repeat string="" times=$node->prevdepth-$node->depth}

{elseif $node->index > 0}
{/if}
{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
current == true}
haschildren == true}
type == 'sectionheader'}
        {$node->menutext}
{elseif $node->type == 'separator'}
       
{else}
type != 'sectionheader' and $node->type != 'separator'}
href="{$node->url}" {if $node->accesskey != ''}accesskey="{$node->accesskey}" {/if}{if $node->tabindex != ''}tabindex="{$node->tabindex}" {/if}{if $node->titleattribute != ''}title="{$node->titleattribute}"{/if}{if $node->target ne ""} target="{$node->target}"{/if}>{$node->hierarchy}: {$node->menutext}
{elseif $node->type == 'sectionheader'}
>{$node->hierarchy}: {$node->menutext}
{/if}

{/foreach}

{repeat string="" times=$node->depth-1}


{/if}

I know nothing about smarty, so can someone please tell me how i have to change the template to add those classes.

Re: smarty fix to add last-child class to menu

Posted: Mon Aug 04, 2008 9:58 pm
by sn3p
I think this won't be easy.. there's no parameter like $node->nextdepth.
Just curious, whats the purpose of this class?

Re: smarty fix to add last-child class to menu

Posted: Tue Aug 05, 2008 4:54 am
by studip101
the point of this was to deal with incompatibility in the css :last-child psuedo class. I already wrote a javascript fix, but figured doing it on the server's side would be better (because the user might have javascript disabled).

Re: smarty fix to add last-child class to menu

Posted: Tue Aug 05, 2008 7:32 am
by alby
studip101 wrote: hi everyone. I need help customizing a menu template so that a class of "last-child" is added to each last, second-level menu item.
Look to smarty manual (.last)

Alby

Re: smarty fix to add last-child class to menu

Posted: Fri Mar 06, 2009 2:04 am
by benchfrooser
Have this problem too, can anybody help to achieve this with the minimal_menu.tpl ?