Implementation details of Smarty foreach control cycle count
- 2020-07-21 07:13:20
- OfStack
Try {$array| count}.
2.
3. Control the number of cycles
2.
{foreach from=$variable key=key name=name iteam=value}
{$variable|@count} // Get the array length
{$smarty.foreach.loop.index} // Gets the subscript of the current loop array element 0 start
{$smarty.foreach.loop.iteration} // Gets the current number of cycles to 1 start
{$smarty.foreach.loop.first} // for true , marking the loop control 1 Time to perform
{$smarty.foreach.loop.last} // for true , marking the end of the loop 1 Time to perform
{$smarty.foreach.name.last} // for true , marking the end of the loop 1 Time to perform
{$smarty.foreach.loop.show} // Currently displayed
{$smarty.foreach.loop.total} // cycles
{/foreach}
3. Control the number of cycles
{foreach name=infolist from=$VIDEO_INFO_LIST item=infolist}
{assign var=floor value=$smarty.foreach.infolist.index}
{if $floor<5%} {* or if $smarty.foreach.infolist.iteration <5*}
<li>{$infolist%}</li>
{/if}
{/foreach}