Utility Filters
General-purpose utility filters.
Default Value
| Filter | Arguments | Description |
|---|---|---|
default | value | Return fallback if empty |
Returns the fallback value if the input is empty (''), null, false, or an empty array.
{{ post.subtitle|default('No subtitle') }}
{{ user.bio|default('No biography available.') }}
{{ item.price|default(0) }}
{{ settings.color|default(theme.primary_color) }}
Note: The default filter treats false and 0 differently:
false→ returns default0→ returns0(not empty)
JSON Encoding
| Filter | Arguments | Description |
|---|---|---|
json_encode | options | Encode value as JSON |
Arguments:
options— JSON encoding options (default: 0)
{{ data|json_encode }}
{{ settings|json_encode }}
Use in data attributes
<div data-config='{{ settings|json_encode }}'>
Pass data to JavaScript
<script>
var config = {{ settings|json_encode }};
</script>
See Expressions & Syntax for a full comparison of ??, ?:, and |default.