Page 1 of 1
Add Smarty counter-tag inside a string [SOLVED]
Posted: Sat Jul 11, 2009 2:29 pm
by DirtyMusic
Hi. I'm not sure if this is the right place to post this message. Admin, feel free to move this to the right category.
I have made a copy and modified the cssmenu.tpl witch comes as a default menu. At one line in the code I want to add a dynamic class because I use jQuery to control my menu.
So what I need is to change this line with code:
Code: Select all
{repeat string="<ul class='i1'>" times=$node->depth-$node->prevdepth}
With something like this:
Code: Select all
{repeat string="<ul class='i{counter name=c1}'>" times=$node->depth-$node->prevdepth}
I have tried some different variations with no luck. Does anyone know how I can add the Smarty counter-tag inside the string?
Re: Add Smarty counter-tag inside a string
Posted: Sat Jul 11, 2009 3:59 pm
by Jeff
try:
{capture assign=count_value}{counter name=c1}{/capture}
{repeat string="" times=$node->depth-$node->prevdepth}
Re: Add Smarty counter-tag inside a string
Posted: Sat Jul 11, 2009 4:29 pm
by DirtyMusic
Thanks ajpro. It worked

With just a small adjustment
Code: Select all
{capture assign=count_value}{counter name=c1}{/capture}
{repeat string="<ul class='i$count_value'>" times=$node->depth-$node->prevdepth}
So for those who want a menu where the sublevel / children is hide and only shows if you click on the parent you can use this code:
Code: Select all
{if $count > 0}
<ul>
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{capture assign=count_value}{counter name=c1}{/capture}
{repeat string="<ul class='i$count_value'>" 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" id="i{counter name=c2}">
{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'}
{if $node->haschildren == true}<span class="fakelink">{$node->menutext}</span>{else}href="{$node->url}"><span>{$node->menutext}</span></a>{/if}
{elseif $node->type == 'sectionheader'}
><span>{$node->menutext}</span></a>
{/if}
{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}
</li>
</ul>
{/if}
Make sure to add
jQuery and this Javascript too:
Code: Select all
<__script__ type="text/javascript">
$(document).ready(function(){
$("li.menuparent").click(function () {
var currentMenuId = this.id;
$('ul.'+currentMenuId).slideToggle(300);
});
});
</__script>