How can I increment a Smarty variable?

前端 未结 6 1051
梦毁少年i
梦毁少年i 2021-02-19 16:02

I am not usually a Smarty guy, so I\'m a bit stuck.

I want to echo the index of an array, but I want to increment it each time I echo it.

This is what I have...<

6条回答
  •  广开言路
    2021-02-19 16:44

    You can do something like the following:

      {foreach from=$gallery key=index item=image name=count}
    • {/foreach}

    Starting from zero, index is the current array index.

    That's probably the best way to go about it, however, to simply use a counter outside of a foreach loop you can use counter, like so:

    {counter start=0 skip=1 assign="count"}
    

    To increment it simply call {counter} at each iteration.

    {counter}
    {*Can then use the $count var*}
       {if $count is div by 4}
          {*do stuff*}
       {/if}
    

提交回复
热议问题