Implementation of Smarty foreach control loop count

Source: Internet
Author: User

1. You can use {$ array | count} to try it.
2.
Copy codeCode: {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
Copy codeThe 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 *}
<Li >{$ infolist %} </li>
{/If}
{/Foreach}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.