Smarty foreach controls the number of cycles

Source: Internet
Author: User

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.

{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

 
{ForeachName = infolist from =$ Video_info_listItem = infolist}{AssignVaR=FloorValue =$ Smarty.Foreach. Infolist. Index}{If $ Floor& Lt; 5% & gt}
{* OrIf $ 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.