This is my code for navigation
这是我的导航代码
<ul class="sortlist">
<li class="first"><strong>{$smarty.const.LBL_SORTBY}: </strong></li>
{foreach $listsortby as $key=>$filterby}
<li class="filterLink"><a href="javascript:void(0);" id="{$key}" class="current" >{$filterby}</a> </li>
{/foreach}
</ul>
and Here I want to get the first key, and add class="current"
这里我想获得第一个键,并添加class =“current”
and rest is empty.
休息是空的。
How to get first value and add class name for first navigation? Thanks in advance
如何获得第一个值并为第一个导航添加类名?提前致谢
1 个解决方案
#1
1
Edited my answer after I found out a better way :)
在我找到更好的方法之后编辑了我的答案:)
{foreach name=listsortby from=$listsortby item=elesortby key=elesortby_key}
<li class="filterLink"><a href="javascript:void(0);"
{if $smarty.foreach.listsortby.first}
class="current"
{/if}
id="{$elesortby_key}">{$elesortby}</a> </li>
{/foreach}
Marcel has also noted in the comments that as of Smarty 3 you can use @first instead of my old hat implementation :)
Marcel在评论中还指出,从Smarty 3开始,您可以使用@first代替我的旧帽子实现:)
{foreach name=listsortby from=$listsortby item=elesortby key=elesortby_key}
<li class="filterLink"><a href="javascript:void(0);"
{if $elesortby@first}
class="current"
{/if}
id="{$elesortby_key}">{$elesortby}</a> </li>
{/foreach}
#1
1
Edited my answer after I found out a better way :)
在我找到更好的方法之后编辑了我的答案:)
{foreach name=listsortby from=$listsortby item=elesortby key=elesortby_key}
<li class="filterLink"><a href="javascript:void(0);"
{if $smarty.foreach.listsortby.first}
class="current"
{/if}
id="{$elesortby_key}">{$elesortby}</a> </li>
{/foreach}
Marcel has also noted in the comments that as of Smarty 3 you can use @first instead of my old hat implementation :)
Marcel在评论中还指出,从Smarty 3开始,您可以使用@first代替我的旧帽子实现:)
{foreach name=listsortby from=$listsortby item=elesortby key=elesortby_key}
<li class="filterLink"><a href="javascript:void(0);"
{if $elesortby@first}
class="current"
{/if}
id="{$elesortby_key}">{$elesortby}</a> </li>
{/foreach}