How can I increment a Smarty variable?

前端 未结 6 1138
梦毁少年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:42

    You can use {counter}

    {counter} is used to print out a count. {counter} will remember the count on each iteration. You can adjust the number, the interval and the direction of the count, as well as determine whether or not to print the value. You can run multiple counters concurrently by supplying a unique name for each one. If you do not supply a name, the name “default” will be used

    source : http://www.smarty.net/docsv2/en/language.function.counter.tpl

    Usage :

    {counter start=0 print=false assign="count"}
    
    
      {foreach from=$listing.products item="product"} {counter} {if $count === 1}

      Count is 1

      {/if} {/foreach}

提交回复
热议问题