This page was printed on Feb 23, 2019. For the current version, visit https://help.shopify.com/en/themes/liquid/tags/control-flow-tags.
Control flow tags create conditions that decide whether blocks of Liquid code get executed.
Executes a block of code only if a certain condition is met (that is, if the result is true).
Like if, but executes a block of code only if a certain condition is not met (that is, if the result is false).
The above example is the same as:
else / elsif
Adds more conditions to an if or unless block.
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.
Multiple conditions (and / or)
You can use the and and or operators to include more than one condition in a control flow tag. and and or can be chained together to create complex conditionals.
If you use multiple and or 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 within Liquid tags and prevent your tags from working.
The and operator lets you add additional conditions to a tag. A condition with an and will only be true if both the left and the right side of the condition are true.
The or operator lets you add additional conditions to a tag. A condition with an or will be true if either the left or the right side of the condition is true.