For loops
This page is for designers who need to repeat something a number of times.
Contents
Syntax
From lib/eztemplate/classes/eztemplateforfunction.php:
{for <number> to <number> as $itemVar [sequence <array> as $seqVar]}
[{delimiter}...{/delimiter}]
[{break}] [{continue}] [{skip}]
{/for}{for 1 to 5 as $i} counts up; {for 5 to 1 as $i} counts down.
Examples
Five stars, filled up to a rating:
<span class="rating" role="img" aria-label="'%count of 5 stars'|i18n( 'design/mytheme',, hash( '%count', $rating ) )|wash">
for 1 to 5 as $star
<span class="starif le( $star, $rating ) is-filled/if" aria-hidden="true"></span>
/for
</span>Page numbers (when you do not use the shipped navigator templates, see Pagination):
for 1 to $page_count as $page
<a href=concat( $node.url_alias, '/(offset)/', $page|dec|mul( $limit ) )|ezurl>$page</a>delimiter /delimiter
/forNotes
- The bounds can be variables and operators:
{for 1 to $items|count as $i}. - For lists,
{foreach}withoffsetandmaxis clearer (Foreach loops).
Related pages
- Foreach loops
- Math operators
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.