Anandhan
Anandhan

Reputation: 432

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 display some messages for the users. so please guide me on how to make the section count.

Upvotes: 0

Views: 18367

Answers (4)

Ravi Patel
Ravi Patel

Reputation: 721

{assign var=val value=0}
{section name=i loop=$data}
         {assign var=val value=$val+1}
{/section}

Upvotes: 0

Htbaa
Htbaa

Reputation: 2309

To get the total count use {$smarty.section.customer.total}

Upvotes: 4

Kamilos
Kamilos

Reputation: 805

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}

Upvotes: 1

JohnP
JohnP

Reputation: 50019

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

Upvotes: 2

Related Questions