Control flow
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 true
.
Input
Output
unless
The opposite of if
– executes a block of code only if a certain condition is not met.
Input
Output
This would be the equivalent of doing the following:
elsif / else
Adds more conditions within an if
or unless
block.
Input
Output
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.
A when
tag can accept multiple values. When multiple values are provided, the expression is returned when the variable matches any of the values inside of the tag. Provide the values as a comma-separated list, or separate them using an or
operator.
An optional else
statement at the end of the case provides code to execute if none of the conditions are met.
Input
Output
Last updated