Conditionals
{else if} branches and at most one {else}. Neither takes a
closing tag; {/if} is required.
null, false, 0, the empty string, the empty array and the empty object
are falsy. An empty array is falsy, which makes {if cart.items} a valid
emptiness check. See Truthiness for the
rest, including why the string "false" is truthy.
Comparisons do not coerce types, so a numeric value that arrived as a string
needs | int before comparison. That is
covered in full here
and is the most common reason an {if} takes the wrong branch.
Loops
{empty} is the branch taken when there is nothing to iterate. It takes no
closing tag, and it is optional: without it an empty collection renders
nothing at all.
To get the index, name it second:
The loop variable
Inside an{each} body, loop is bound automatically. It has exactly four
fields:
loop. loop.even, loop.odd, loop.length,
loop.index0, loop.revindex and loop.parent all resolve to null and render
the empty string, so a habit from Jinja or Twig fails silently here. For
alternating rows, compare loop.index % 2.
In nested loops the inner loop shadows the outer one, and there is no way to
reach the outer loop from inside. Name the outer index instead, because a
named binding is not shadowed:
Collections that are not arrays
A null or missing collection is empty and takes the{empty} branch:
cart.items is [], null, or absent from the context
entirely. A misspelled collection name therefore renders the empty state, not an
error. An empty state appearing for no reason is often a misspelled name.
A value that is neither an array nor null is wrapped and iterated exactly once,
with loop.count of 1. So {each} over a single object makes one pass rather
than none.
Filtering and ordering
The{each} header accepts loop filters, which run before iteration:
Matching
->, then a body. _ is the wildcard.
Patterns are string, number or boolean literals only. Matching is type-strict,
so a "1" pattern never matches a numeric 1, exactly as == behaves.
With no matching arm and no _, the block renders nothing at all. Against a
status of archived, this produces an empty file:
_ arm unless
the silence is intended.
Repeat
order.total of "3":
Fetch
{fetch} declares a data dependency with branches for each state.
The compiler performs no network request, ever. Rendering makes no I/O at
all.
{fetch} reads the name out of the render context and picks a branch.
On a static build a
{fetch} whose name is absent from the globals renders its
{loading} branch. That is the skeleton state, and it is also what a typo in
the name produces.
The branch order is fixed: body, then {loading}, then {error}, then
{empty}. Out of order is not recovered and reports as an unclosed block. All
four branches beyond the body are optional.
Options are cache(n), retry(n), timeout(n), poll(n), paginate(n),
infinite(n) and the flag abort-on-navigate. They are recorded for the
browser runtime and have no effect on the server render. An unrecognised option
is silently dropped, so check the spelling.
{with} does not exist
Twig, Nunjucks and Blade provide a scoping block. Slurp has none.
{with} is a hard
build failure, and the four errors after the first are the parser recovering
from it.
Write the full path instead. Where the repetition is heavy, {each} over a
non-array value iterates it exactly once, which gives the shorter name:
The iteration budget
Every loop is capped at 1000 iterations, and a whole render is capped at 1,000,000 across all loops. Exceeding a cap truncates. It never aborts the render, so a page over budget still builds, still exits 0, and simply loses the tail of the list.{repeat} clamps to 1000 with no diagnostic at all, in either mode. Check the
count when generating a large number of elements from one.
Paginate server-side rather than relying on either cap. The budgets bound a
hostile or broken template; they are not a paging strategy. The full list is in
Limits.
Next
Filters
The loop filters used in
{each} headers, and the value filters.Displaying data
Truthiness and comparison rules.
Block tags
Every tag, with branch order and closing rules.
Common mistakes
The silent failures, collected in one place.