Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,075 of 9,075 pages
About the help in other languages
All help pages

For loops

Counting loops with for: from a number to a number, counting down, sequences, and typical uses such as star ratings, placeholders and page numbers.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/for-loops.md

On this page

For loops

This page is for designers who need to repeat something a number of times.

Contents

  1. Syntax
  2. Examples
  3. Notes

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="star{if 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}
{/for}

Notes

  • The bounds can be variables and operators: {for 1 to $items|count as $i}.
  • For lists, {foreach} with offset and max is clearer (Foreach loops).

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.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x