Variable
Variable tags create new Liquid variables.
assign
Creates a new named variable.
Input
Output
Wrap a value in quotations "
to save it as a string variable.
Input
Output
capture
Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created using capture
are stored as strings.
Input
Output
Using capture
, you can create complex strings using other variables created with assign
.
Input
Output
increment
Creates and outputs a new number variable with initial value 0
. On subsequent calls, it increases its value by one and outputs the new value.
Input
Output
Variables created using increment
are independent from variables created using assign
or capture
.
In the example below, a variable named “var” is created using assign
. The increment
tag is then used several times on a variable with the same name. Note that the increment
tag does not affect the value of “var” that was created using assign
.
Input
Output
decrement
Creates and outputs a new number variable with initial value -1
. On subsequent calls, it decreases its value by one and outputs the new value.
Input
Output
Like increment, variables declared using decrement
are independent from variables created using assign
or capture
.
Last updated