default Filter

Lets you specify a fallback in case a value doesn’t exist.

Parameters

Parameter Required Description
default_value Yes string Value to return if the left side doesn’t exist.

Category

Base Filters

Description

The default filter lets you specify a fallback in case a value doesn’t exist. default will show its value if the left side is nil, false, or an empty string.

Example: price is not defined, so the default value is used
{{ price | default: 2.99 }}

Output

2.99
Example: price is defined, so the default value is not used
      {% assign price = 4.99 %}
      {{ price | default: 2.99 }}
      

Output

4.99
Example: price is empty, so the default value is used
      {% assign price = '' %}
      {{ price | default: 2.99 }}
      

Output

2.99