Smarty - foreach loop 10 times and stop

后端 未结 8 2295
执念已碎
执念已碎 2021-02-07 12:31

Im using the following Smarty code:

{foreach from=$entries key=i item=topic}
  {if $topic.topic_style == question}
    
  • 8条回答
    •  失恋的感觉
      2021-02-07 12:55

      Smarty 3 has another option, if at all possible then upgrading would be advisable. If you can't then speaking to the developer of your application.

      {foreach $result_set as $result}
          {if $result@iteration lte 10}
              // just as in php both forms of access are available.
              {$result.assoc_key}
              {$result.0}
          {/if}
      {/foreach}
      

      Its also worth noting that Smarty 3 has {break} built in too. However, if you are breaking from the foreach loop before the end and essentially discarding the remaining data then you might want to consider if its possible to LIMIT your sql queries.

    提交回复
    热议问题