Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Just exceptional. Thank you so much, Jack, you smashed it.

— Hugo, Developer

Loop Tag

Create and iterate through a loop a specific number of times or between a range.

Overview

Create and iterate through a loop a specific number of times using the times parameter, or through a range with the from and to parameters. Do not use both. It'll make a weird mess.

Examples

Count to 10

{{ loop times="10" }}
{{ value }}
{{ /loop }}
<s:loop times="10">
{{ $value }}
</s:loop>

Looping a variable number of times

---
number: "5"
text: "Pow"
---
 
{{ loop :times="number" }}
{{ text }}
{{ /loop }}
 
// Output: PowPowPowPowPow
<?php
$number = 5;
$text = 'Pow';
?>
 
<s:loop :times="$number">
{{ $text }}
</s:loop>
 
// Output: PowPowPowPowPow

Populate a select field with years

<select name="year">
{{ loop from="1900" to="2020" }}
<option value="{{ value }}">{{ value }}</option>
{{ /loop }}
</select>
<select name="year">
<s:loop from="1900" to="2020">
<option value="{{ $value }}">{{ $value }}</option>
</s:loop>
</select>

Parameters

times

int

Number of times to loop.

from

int

Number to start looping from. Default 1.

to

int

Number to stop looping at.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →