Deliberate Differences and Non-Goals
Clarity draws inspiration from Twig and Phalcon's Volt. This page documents intentional differences and non-goals.
Differences from Twig
{% elsefor %} exists as well as {% else %}
Twig uses {% else %} for both loops and conditionals. Clarity also supports
{% elsefor %} (from Volt), which unambiguously marks a loop's empty branch.
Either form is allowed, but a loop can have only one.
{% for x in y if cond %} is supported
Twig removed this in version 3 and recommends filtering the sequence instead. Clarity retains the syntax and evaluates the condition per iteration, as Twig 2 did.
Clarity has no loop variable, and evaluates the condition on each iteration.
The |> filter pipe remains available when you need a filtered sequence.
{% caller %} is a directive, not caller()
Twig uses caller() as a function that accepts arguments from the call tag.
Clarity uses the {% caller %} directive because the slot is source text compiled
at that location, not a value.
The body sees the macro's parameters directly, so {% caller %} needs no arguments
and has no arity restriction.
Nested blocks are allowed
A block may be nested inside another block. Twig supports this; Volt does not. Clarity matches overrides by name at any depth.
Duplicate block names in one template are allowed
The same block may appear in multiple locations, allowing one override to fill
each—for example, both a <meta> element and <title>.
Differences from Volt
Operator precedence is grouped, not left to PHP
Volt gives * / % lower precedence than + - ~, but emits PHP operators without
parentheses. Thus 1 + 2 * 3 parses as (1 + 2) * 3 but PHP evaluates it as
1 + (2 * 3). Clarity emits explicit grouping so the result matches the parse tree.
switch output before the first label is a compile error
Volt emits the text and leaves PHP to report a syntax error. Clarity reports non-whitespace output before the first label at the template line and drops whitespace-only text.
Nested switch is allowed
Volt rejects nested switches. PHP supports them, and Clarity tracks nested levels.
{% break %} / {% continue %} are built in
Both are supported in loops; break also works in switches. Twig has neither.
They accept PHP's numeric levels, such as {% break 2 %}. Volt does not support
levels; its handlers emit bare break or continue and ignore a specified level.
Clarity preserves levels so a break inside a switch can also exit its enclosing loop.
{% verbatim %} is a scanner mode
The body is not tokenized, so its contents cannot affect template structure. The directive works with whitespace control, comments, and inheritance.
Non-goals
- No
loopvariable. Clarity does not provideloop.index,loop.first,loop.parent, or related values, avoiding per-iteration object allocation. Use{% for key, value in … %}to access keys or indexes. - No
{% with %}block. Each render has one scope. Assignments inside conditionals, loops, blocks, macros, and included templates remain visible afterwards; macros are inlined and do not create a scope. Use asetpreamble or macro parameters to reuse values. - Content outside child blocks is ignored. With
{% extends %}, only the child's blocks are used. This documented behavior is retained for compatibility.