Control flow tags

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

if

Executes a block of code only if a certain condition is met (that is, if 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 executes a block of code only if a certain condition is not met (that is, if the result is false).

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

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 to execute a particular block of code when a variable has a specified value. case initializes the switch statement, and when statements define the various conditions.

You can optionally add an else statement at the end of the case to provide code to execute if none of the conditions are 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.