This article mainly introduces some methods to control the number of cycles in Smartyforeach. This article also summarizes some methods to obtain the current number of times. For more information, see
This article mainly introduces some methods for controlling the number of cycles in Smarty foreach. This article also summarizes some methods for obtaining the current number of times. For more information, see
1. arrays in smarty are often used. to traverse arrays cyclically, use section or foreach. How can we get the array length or determine the number of arrays? You can use {$ array | count} to try it.
2.
The Code is as follows:
{Foreach from = $ variable key = key name = name iteam = value}
{$ Variable | @ count} // obtain the array Length
{$ Smarty. foreach. loop. index} // gets the element subscript of the current loop array, starting with 0
{$ Smarty. foreach. loop. iteration} // gets the number of current cycles, starting with 1
{$ Smarty. foreach. loop. first} // if it is true, mark the first execution of the loop
{$ Smarty. foreach. loop. last} // if it is true, mark the last execution of the loop
{$ Smarty. foreach. name. last} // if it is true, mark the last execution of the loop
{$ Smarty. foreach. loop. show} // whether the current display is displayed
{$ Smarty. foreach. loop. total} // number of cycles
{/Foreach}
3. Control the number of cycles
The Code is as follows:
{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 *}
{$ Infolist %}
{/If}
{/Foreach}