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.
{% if rental.title == 'Apartment 051' %}
This Apartment comes with a swimming pool.
{% endif %}
This Apartment comes with a swimming pool.
Adds more conditions within an if
or unless
block.
<!-- 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.
{% assign handle = 'Apartment 4129' %}
{% case handle %}
{% when 'Apartment 4129' %}
It is an Apartment 4129
{% when 'Apartment 5100' %}
It is an Apartment 5100
{% else %}
This is not an Apartment 4129 nor a Apartment 5100
{% endcase %}
It is an Apartment 4129
Similar to if
, but executes a block of code only if a certain condition is not met.
{% unless rental.title == 'Apartment 051' %}
This Apartment is without a swimming pool.
{% endunless %}
This Apartment is without a swimming pool.
This would be the equivalent of doing the following:
{% if rental.title != 'Apartment 051' %}
This Apartment is without a swimming pool.
{% endif %}