The default filter defines a fallback value to be rendered in place of a variable when that variable evaluates to nil, false, or an empty string (""). This ensures that the output remains meaningful even when the underlying data is absent or undefined.
{{ name | default: "there" }}
{{ c_loyalty_tier | default: "standard" }}
{{ c_total_orders | default: 0 }}Data type
String
Hello {{ name | default: "Dear Customer" }},Boolean
{% assign is_member = c_loyalty_tier != blank %}
{% if is_member %}
Member content.
{% else %}
Non-member content.
{% endif %}Number
{% assign order_count = c_total_orders | default: 0 %}
{% if order_count > 0 %}
You have placed {{ order_count }} orders.
{% else %}
You have not placed any orders yet.
{% endif %}What triggers default?
Value | Triggers default? | Treated as false in if? |
|---|---|---|
nil (not set) | Yes | Yes |
false | Yes | Yes |
"" (empty string) | Yes | No — it is truthy |
" " (whitespace) | No | No |
0 | No | No — 0 is truthy |
[] (empty array) | Yes | No |
The key difference between default and if conditions is that they do not behave the same way for all values. An empty string ("") triggers default, but is truthy in an if condition. Use default when you want a fallback for missing data. Use != blank or explicit comparisons in if conditions.
The number 0 does not trigger default and is truthy in conditions. Use {% if count > 0 %} if you want to exclude zero.