Page 1 of 1

[SOLVED] Adding a class on last child of a submenu ?

Posted: Sun Oct 25, 2009 3:35 pm
by Trangsene
Hello,
I'm using cssmenu.tpl and I would like to have a class "last" on the last child of a submenu to have no separator after it.

Here is the cssmenu 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}
{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' and $node->haschildren == true}
<li class="sectionheader"><span class="sectionheader">{$node->menutext}</span>{elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="menu_separator" />{else}
<li>
<a {/if}
{if $node->type != 'sectionheader' and $node->type != 'separator'}
{if $node->target}target="{$node->target}" {/if}
href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->type == 'sectionheader'}
><span class="sectionheader">{$node->menutext}</span></a>
{/if}
{/foreach}
{repeat string='</li></ul>' times=$node->depth-1}
</li>
</ul>
<div class="clearb"></div>
</div>
{/if}
After this:

Code: Select all

{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
I need to have the total of the children of the current node and test if we have reached the last child in order to write "<a href..."

I'm searching a solution for hours, did anyone try to solve this problem and succeed ?
Help would be much appreciated.

Thanks in advance.

Re: Adding a class on last child of a submenu ?

Posted: Sun Oct 25, 2009 5:09 pm
by Connie
I think you are a little bit away from the solution, but not too far...

think of "pseudo-classes" and use "last child" instead.. the system will find automatically the last one ;=)

Code: Select all

li:last-child{color:#ff0000}

Re: Adding a class on last child of a submenu ?

Posted: Sun Oct 25, 2009 7:06 pm
by Trangsene
Thanks, I know last and first-child in CSS but this won't work in IE6 and this website has to :-(
Anyway having a code based solution would be interesting for other uses.

Re: Adding a class on last child of a submenu ?

Posted: Mon Oct 26, 2009 1:00 pm
by Connie
this won't work in IE6 and this website has to :-(
Is this really true? Shouldn't webworkers stop to support this shitty browser?

Time has come, or do the people are still on WIN 3.11 and read newspapers from 1997?

Cheers., and good luck,

Connie

Re: Adding a class on last child of a submenu ?

Posted: Mon Oct 26, 2009 1:25 pm
by Ziggywigged

Re: Adding a class on last child of a submenu ?

Posted: Mon Oct 26, 2009 5:34 pm
by Trangsene
Generally I prefer avoid this kind of js solution if I can.
This time I think this will be the quicker way.
Thanks four your answers.

Anf for information first-child is understood by IE8 but last-child absolutly not !

Re: [SOLVED] Adding a class on last child of a submenu ?

Posted: Mon Oct 26, 2009 11:27 pm
by Dr.CSS
You could try this one from Calguy, you can change the menuparent etc. if need be...

{if $count > 0}


{* begin calguy *}
{foreach from=$nodelist item=node name='menu'} 
{assign var='last' value=''}
{if $smarty.foreach.menu.last}
  {assign var='last' value='last '}
{/if}
{* end calguy *}
{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'}
       
{elseif empty($last)}
        {* not the last menu item, but not a separator, header, parent, or active either *}
        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}