Skip to main content

Utility Filters

General-purpose utility filters.

Default Value

FilterArgumentsDescription
defaultvalueReturn 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 default
  • 0 → returns 0 (not empty)

JSON Encoding

FilterArgumentsDescription
json_encodeoptionsEncode 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.