default - Liquid Filter Reference - 0.11.3
Filter Name | default |
Group | Utilities |
Version | 0.11.3 |
Description
Sets a default value for any variable which is nil
, false
, or blank
.
Examples
{{ quantity | default: 5 }}
5
In this example, price is defined, so the default value is not used:
{% assign price = 4.99 %}
{{ price | default: 2.99 }}
4.99
In this example, price is empty, so the default value is used:
{% assign price = "" %}
{{ price | default: 2.99 }}
2.99
Options
allow_false
To allow variables to return false instead of the default value, you can use the allow_false
parameter.
{% assign hide_price = false %}
{{ hide_price | default: true, allow_false: true }}
false
Back to Liquid Reference for 0.11.3
Back to Documentation