Control Flow tags determine which block of code should be executed based on different conditions.
Executes a block of code only if a certain condition is met.
Input
{% if product.title == 'Awesome Shoes' %} These shoes are awesome! {% endif %}
Output
These shoes are awesome!
Adds more conditions within an if or unless block.
if
unless
<!-- If customer.name = 'anonymous' --> {% if customer.name == 'kevin' %} Hey Kevin! {% elsif customer.name == 'anonymous' %} Hey Anonymous! {% else %} Hi Stranger! {% endif %}
Hey Anonymous!
Creates a switch statement to compare a variable with different values. case initializes the switch statement, and when compares its values.
case
when
{% assign handle = 'cake' %} {% case handle %} {% when 'cake' %} This is a cake {% when 'cookie' %} This is a cookie {% else %} This is not a cake nor a cookie {% endcase %}
This is a cake
Similar to if, but executes a block of code only if a certain condition is not met.
{% unless product.title == 'Awesome Shoes' %} These shoes are not awesome. {% endunless %}
These shoes are not awesome.
This would be the equivalent of doing the following:
{% if product.title != 'Awesome Shoes' %} These shoes are not awesome. {% endif %}
Was this article helpfu?
Thank you for voting
You are related to multiple companies. Please select the company you wish to login as.