Liquid Tags: Variables

Last updated on June 18, 2024

Variables (no matter how they are defined) in Insites are local. This means that a variable defined inside a partial is not available on a page that includes it. To export variables from a partial read about the export tag.

This article discusses the following topics:

  • assign
  • capture
  • increment
  • decrement

assign

Creates a new named variable.

Input

Output

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:

Input

Output

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 , you can create complex strings using other variables created with assign. Outputting data from a tag results in stripped HTML.

Input

Output

increment

Creates a new number variable, and increases its value by 1 every time 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:

Input

Output

Variables created using are separate from variables created using or .

In the example below, a variable named is created using assign. The increment tag is then used several times on a variable with the same name. Note that the tag does not affect the value of that was created through .

Input

Output

decrement

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

Input

Output

Like , variables declared using are independent from variables created using or .

Note

This topic is a compilation of knowledge found at Shopify Themes, Liquid Documentation, Liquid Gem Documentation, and Liquid for Designers.

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.