Skip to content

unless

The opposite of if, we output the encapsulated block only if the evaluated condition is falsy.

TIP

Similarly to if, you can use elseif to handle more conditions.

liquid
{% unless condition %}
  block_to_output
{% endunless %}
  • condition: Falsy condition to evaluate.
  • block_to_output: Rendered expression in case the condition is met.

Example

Data
json
{
  "product": {
    "track_inventory": true
  }
}

Note: Data is only refereed as a reference for this example and is in no means reflecting real world data.

liquid
{% unless product.track_inventory == false %}
  <span>Supply is limited. Hurry up!</span>
{% endunless %}

Output

Supply is limited. Hurry up!