1

I want to do one counter with Smarty.

In php I do $i++ to create a counter and after I use if() with if($i%3 == 0).

How could I do the same but with Smarty?

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
oiram16
  • 95
  • 1
  • 9

1 Answers1

0

To initialise a counter in Smarty, you just need to specify the variable, and optionally provide the start point and skip (incremental offset):

{counter start=0 skip=3 assign=var} // Initialise the counter **and** log the first output
{counter}<br />
{counter}<br />
{counter}<br />

This will start a counter at 1, and increment by 3, so this will output:

1<br />
4<br />
7<br />
10<br />

Then you can check if a particular number in the counter is divisible by three with:

{if $var is div by 3}
   ...
{/if}

Hope this helps! :)

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • Coud you help me with my code? {if empty($tsCategorias)}
    No hemos creado categorías en el sistema de ayuda
    {else} {counter start=0 skip=3 assign=i} {foreach from=$tsCategorias item=c} {/foreach} {if $i is div by 3} {/if}
    {$c.c_nombre} ()
    {/if}
    – oiram16 Sep 25 '17 at 03:57