Developers · Liquid
Liquid Tags: Variables
Last updated 2 November 2026
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
{% assign favorite_food = "apples" %}
My favorite food is {{ favorite_food }}.Output
My favorite food is apples.You can assign a string, a number, a boolean, a hash or an array, for example
Input
{% assign first_time_visitor = true %}
{% if first_time_visitor == true %}
Welcome to the site!
{% endif %}Output
Welcome to the site!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
Input
{% assign favorite_food = "pizza" %}
{% assign age = 35 %}
{% capture about_me %}
I am {{ age }} and my favorite food is {{ favorite_food }}.
{% endcapture %}
{{ about_me }}Output
I am 35 and my favorite food is pizza.increment
Creates a new number variable, and increases its value by 1 every time
Here, an increment counter is used to create a unique numbered class for each list item:
Input
<ul>
<li class="item-{% increment counter %}">apples</li>
<li class="item-{% increment counter %}">oranges</li>
<li class="item-{% increment counter %}">peaches</li>
<li class="item-{% increment counter %}">plums</li>
</ul>Output
<ul>
<li class="item-0">apples</li>
<li class="item-1">oranges</li>
<li class="item-2">peaches</li>
<li class="item-3">plums</li>
</ul>Variables created using
In the example below, a variable named
Input
{% assign my_number = 10 %}
{% increment my_number %}
{% increment my_number %}
{% increment my_number %}
{{ my_number }}Output
0
1
2
10decrement
Creates a new number variable, and decreases its value by 1 every time
Input
{% decrement variable %}
{% decrement variable %}
{% decrement variable %}Output
-1
-2
-3Like
Note
This topic is a compilation of knowledge found at Shopify Themes, Liquid Documentation, Liquid Gem Documentation, and Liquid for Designers.
Try it
Edit the input and press Run. The example runs on this site, read-only.