{% unless %}

The opposite of the if tag, use the unless tag to only execute a block of code if a certain condition is NOT met.

The unless tag does not have an equivalent for the {% elsif %} or {% else %} blocks.

To end an unless block, use {% endunless %}

Syntax

{% unless condition %}...{% endunless %}

You can use the and and or operators to include more than one condition. These can be chained together to create complex conditionals.

If you use multiple and and or operators, note that and operators will be evaluated first, then or operators. You cannot use parentheses to simulate an order of operations and control the order of operator evaluation. Parentheses are invalid characters and will prevent your tags from working.

The unless tag creates a new child scope.

Condition

The unless condition is evaluated exactly the same as the {% if %} conditions, except that the unless block is only executed if the condition is NOT met.

Examples

{% unless blog_post.summary_html.is_valid  %}
    Summary still needs to be written.
{% endunless %}

Developer Overview

Liquid Markup