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).

unless

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. To learn about the order in which these operators are checked, refer to the Operators reference.

and

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.

or

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.