Control flow tags create conditions that decide whether blocks of Liquid code run.

if

Runs a block of code only if a condition is met (the result is true).

{% if product.title == 'Awesome Shoes' %}
  You are buying some awesome shoes!
{% endif %}
You are buying some awesome shoes!

unless

Like if, but runs a block of code only if a condition is not met (the result is false).

{% unless product.title == 'Awesome Shoes' %}
  You are not buying awesome shoes.
{% endunless %}
You are not buying awesome shoes.

This is the same as:

{% if product.title != 'Awesome Shoes' %}
  You are not buying awesome shoes.
{% endif %}

else / elsif

Adds more conditions to an if or unless block.

{% if shipping_method.title == 'International Shipping' %}
  You're shipping internationally. Your order should arrive in 2–3 weeks.
{% elsif shipping_method.title == 'Domestic Shipping' %}
  Your order should arrive in 3–4 days.
{% else %}
  Thank you for your order!
{% endif %}
Your order should arrive in 3–4 days.

case / when

Creates a switch statement that runs a specific block of code when a variable has a specific value. case starts the switch statement, when defines the conditions.

You can add an optional else at the end to provide code that runs when none of the conditions is met.

{% case shipping_method.title %}
  {% when 'International Shipping' %}
    You're shipping internationally. Your order should arrive in 2–3 weeks.
  {% when 'Domestic Shipping' %}
    Your order should arrive in 3–4 days.
  {% when 'Local Pick-Up' %}
    Your order will be ready for pick-up tomorrow.
  {% else %}
    Thank you for your order!
{% endcase %}
Your order should arrive in 3–4 days.

Multiple conditions (and / or)

Use the and and or operators to include more than one condition in a control flow tag. You can chain and and or to build complex conditions. See the operators reference for the order in which they are evaluated.

and

The and operator adds conditions to a tag. A condition with and is only true if both the left and the right side are true.

{% if line_item.grams > 20000 and customer_address.city == 'Hannover' %}
  You are buying a heavy item and live in the same city as our store. Choose local pick-up as shipping option to avoid high shipping costs.
{% endif %}
You are buying a heavy item and live in the same city as our store. Choose local pick-up as shipping option to avoid high shipping costs.

or

The or operator adds conditions to a tag. A condition with or is true if either the left or the right side is true.

{% if customer.tags contains 'VIP' or customer.email contains 'mycompany.com' %}
  Welcome! We're pleased to offer you a special discount of 15% on all products.
{% else %}
  Welcome to our store!
{% endif %}
Welcome! We're pleased to offer you a special discount of 15% on all products.