Smarty loop count
I am new to smarty concepts. I have used section loop in my tpl page to show the user data, in this page i need the section count.
For example:
{section name=i loop=$getFriends start=0 step=1}
{/section}
I need to check the section count for the array values($getFriends) to 开发者_如何学Godisplay some messages for the users. so please guide me on how to make the section count.
To get the total count use {$smarty.section.customer.total}
By 'count' do you mean the current index of the loop?
If so you can use this
{section name=customer loop=$custid}
{$smarty.section.customer.index} id: {$custid[customer]}<br />
{/section}
http://www.smarty.net/docsv2/en/language.function.section.tpl#section.property.index
Try {counter} http://www.smarty.net/docsv2/en/language.function.counter.tpl Exapmle:
{counter start=0 print=false name=bla}
{section name=i loop=$getFriends start=0 step=1}
{counter}
{/section}
{assign var=val value=0}
{section name=i loop=$data}
{assign var=val value=$val+1}
{/section}
精彩评论