default - Liquid Filter Reference
On this page
Description
Sets a default value for any variable which is nil, false, or blank.
| Property | Value |
|---|---|
| Return Type | any |
| Category | utilities |
Options
| Option | Description |
|---|---|
allow_false |
To allow variables to return false instead of the default value, you can use the allow_false parameter. |
Examples
liquid
{{ quantity | default: 5 }}
Output: 5
In this example, price is defined, so the default value is not used
liquid
{% assign price = 4.99 %}
{{ price | default: 2.99 }}
Output: 4.99
In this example, price is empty, so the default value is used
liquid
{% assign price = "" %}
{{ price | default: 2.99 }}
Output: 2.99