Conditionals: @if, @else, @elseif, @endif
Show one block when a condition is true, optionally with else branches.
@if(condition)— Renders the following content only when the condition is truthy.@else— Optional; rendered when the@ifcondition is false.@elseif(condition)— Optional; additional condition; first matching branch is used.@endif— Ends the conditional block.
Conditions
You can use:- Word operators (safe in HTML):
eq,neq,lt,lte,gt,gte
Example:@if(orders.length gt 0) - Symbols (where allowed):
===,!==,==,!=,<=,>=,<,> - Logic:
and,or, unary! - Property checks:
@if(article.author_avatar),@if(related_articles && related_articles.length)
@elseif and array length:
Loops: @foreach … @endforeach
Repeat a block once per element in an array.
@foreach(item in array)—itemis the variable name for the current element;arrayis an expression that must evaluate to an array (e.g.posts,related_articles).@endforeach— Required; ends the loop.
{{ item.property }}, @if, nested @foreach, and filters.
Variables: @set
Define a variable for use later in the template.
Components: @component
Include a reusable component by name, with optional arguments.
Inheritance: @extends and @block
Use a base template and override only certain regions.
Base template (e.g. layout)
The base defines named blocks that child templates can override:Child template
The child declares which base it extends and redefines one or more blocks:@extends("pageSlug")— Must be at the top; use the base page’s slug.@block("name")…@endblock— Replaces the same-named block in the base. Only the blocks you define are overridden; the rest of the base layout is used as-is.
Summary
| Directive | Purpose |
|---|---|
@if(condition) … @endif | Conditional block |
@else / @elseif(condition) | Else branches |
@foreach(item in array) … @endforeach | Loop |
@set(variable = expression) | Set variable |
@component("name", args) | Include component |
@extends("pageSlug") | Extend base template |
@block("name") … @endblock | Define/override block |