Variable tags

You can use variable tags to create new Liquid variables.

assign

Creates a new named variable.

assigned variables can be strings or booleans (true or false). Remember not to use quotation marks around the value if it is true or false:

capture

Captures the string inside of the opening and closing tags and assigns it to a variable. Variables that you create using capture are stored as strings.

Using capture, you can create complex strings using other variables created with assign.

increment

Creates a new number variable, and increases its value by 1 every time increment is called on the variable. The counter's initial value is 0.

Here, an increment counter is used to create a unique numbered class for each list item:

Variables created using increment are separate from variables created using assign or capture.

In the example below, a variable named my_number 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 my_number that was created through assign.

decrement

Creates a new number variable, and decreases its value by 1 every time decrement is called on the variable. The counter's initial value is -1.

Like increment, variables declared using decrement are independent from variables created using assign or capture.