Core Functions
| Function | Description | Example |
|---|---|---|
min | Smallest value | {{ min(1, 2, 3) }} or {{ min(prices) }} |
max | Largest value | {{ max(1, 2, 3) }} or {{ max(prices) }} |
random | Random value | {{ random() }} or {{ random(items) }} |
range | Generate a sequence | {{ range(1, 10) }} or {{ range(0, 100, 5) }} |
cycle | Cycle through values | {{ cycle(['odd', 'even'], loop.index) }} |
date | Create a timestamp | {{ date() }} or {{ date('now') }} |
html_classes | Conditional CSS classes | {{ html_classes('btn', {active: true}) }} |
min / max
Accept either multiple arguments or an array:
{{ min(10, 5, 20) }} → 5
{{ max(10, 5, 20) }} → 20
{{ min(prices) }} → smallest in array
{{ max(prices) }} → largest in array
random
Returns a random value. Without arguments, returns a random number. With an array, returns a random element:
{{ random() }}
{{ random(['red', 'green', 'blue']) }}
range
Generates a sequence of numbers:
{{ range(1, 5) }} → [1, 2, 3, 4, 5]
{{ range(0, 100, 10) }} → [0, 10, 20, ..., 100]
cycle
Cycles through an array based on an index — useful in loops for alternating values:
{{ cycle(['odd', 'even'], loop.index) }}
{{ cycle(['primary', 'secondary', 'accent'], loop.index) }}
date
Creates a timestamp value that can be formatted with the date filter:
{{ date()|date('Y-m-d') }}
{{ date('now')|date('F j, Y') }}
html_classes
Generates a space-separated class string. Strings are always included, objects include the key only when the value is truthy:
{{ html_classes('btn', {active: is_active, disabled: is_disabled}) }}
If is_active is true and is_disabled is false, the output is btn active.