All posts

Tutorial

How to set fallback values in Shopify Liquid (the default filter)

Stop empty fields from leaving holes in your theme. Here's how Shopify's default filter works, the difference between empty, blank, and nil, and the allow_false gotcha that catches everyone with booleans.

Bas Lefeber

Founder, learnshopify.dev · May 7, 2026 · 1 min read

Real stores have messy data: a product with no description, a metafield nobody filled in, a setting left blank. If your theme renders those gaps as empty space or a stray label, it looks broken. The default filter is the clean fix — one fallback value when the source is empty.

The default filter

sections/product.liquid
{{ product.metafields.specs.origin | default: "Origin coming soon" }}

If the metafield has a value, you get it. If it's empty, nil, or an empty string, you get the fallback. One expression, no if block.

empty, blank, and nil

To use default well, it helps to know what counts as "nothing" in Liquid:

  • nil — the value doesn't exist at all (an undefined object or unset field).
  • empty — an empty string, array, or object.
  • blank — the catch-all: nil, empty, or a string of only whitespace. This is what you usually test in an if.
liquid
{% if product.description != blank %}  {{ product.description }}{% else %}  <p>No description yet.</p>{% endif %}

Tip

Use default for a simple inline fallback, and if ... != blank when the fallback needs its own markup (a different element, a class, a whole block).

The boolean gotcha: allow_false

default treats false as empty

By default, default replaces false with the fallback — which is wrong when false is a real, intended value (a toggle that's off). Pass allow_false: true so a genuine false survives:

liquid
{{ settings.show_badge | default: true, allow_false: true }}

What AI tools get wrong here

Two things. AI suggestions reach for a verbose if/else where a one-line default would do, and they forget allow_false on boolean settings — so a toggle that's switched off silently flips back to the default. Knowing the blank family and the allow_false flag is the difference.

Learn this properly · free lesson

Fall back gracefully when product descriptions are empty

Add a graceful fallback to a real product field in the interactive editor and see exactly when default fires. Free lesson — try it without an account.

Try this lesson — free

Frequently asked questions

What does the default filter do in Shopify Liquid?

It outputs a fallback value when the input is nil, an empty string, or false. {{ value | default: "fallback" }} returns the value if present, otherwise the fallback.

What's the difference between empty, blank, and nil?

nil means the value doesn't exist; empty means an empty string/array/object; blank is the catch-all covering nil, empty, and whitespace-only strings. Test against blank in most if statements.

Why is my false value being replaced by the default?

Because default treats false as empty by default. Add allow_false: true — e.g. {{ setting | default: true, allow_false: true }} — so an intentional false is preserved.

Should I use default or an if statement?

Use default for a simple inline fallback value. Use if ... != blank when the fallback needs different markup, a different element, or a class change.

LiquidString filtersDefensive code

Keep going in the curriculum