Implementation of Smarty foreach control cycle times

Source: Internet
Author: User
Tags foreach array length
Arrays are often used in smarty, looping through the array with section or foreach, how to get the length of the array or to determine the number of an array

1. You can use {$array | count} to try it.
2.

Copy Code code as follows:


{foreach from= $variable key=key name=name Iteam=value}


{$variable | @count}//Get array length


{$smarty. Foreach.loop.index}//Get subscript of the current loop array element, starting with 0


{$smarty. foreach.loop.iteration}//Get the current number of loops, starting at 1


{$smarty. Foreach.loop.first}//Is True, the token loop executes for the first time


{$smarty. Foreach.loop.last}//Is True, the token loop executes the last


{$smarty. Foreach.name.last}//Is True, the token loop executes the last


{$smarty. foreach.loop.show}//Current display


{$smarty. Foreach.loop.total}//Cycle times


{/foreach}


3. Control cycle Times

Copy Code code 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.