Predefined Liquid objects can be overridden by variables with the same name. To make sure that you can access all Liquid objects, make sure that your variable name doesn’t match a predefined object’s name.

assign

Creates a new variable. You can create variables of any type, including strings, numbers, arrays, and objects.
{% assign variable_name = value %}
variable_name
string
The name of the variable to create.
value
string
The value to assign to the variable.
{% assign username = "John" %}
{% assign age = 25 %}
{% assign is_admin = true %}
{% assign favorite_colors = "red,blue,green" | split: "," %}

Username: {{ username }}
Age: {{ age }}
Admin status: {{ is_admin }}
First favorite color: {{ favorite_colors[0] }}
Username: John
Age: 25
Admin status: true
First favorite color: red

capture

Captures the string inside the tag and assigns it to a variable. The capture tag is useful when you want to combine multiple values into a single string.
{% capture variable_name %}
  content_to_capture
{% endcapture %}
variable_name
string
The name of the variable to create.
content_to_capture
string
The content to capture and assign to the variable.
{% assign first_name = "John" %}
{% assign last_name = "Doe" %}

{% capture full_name %}
  {{ first_name }} {{ last_name }}
{% endcapture %}

Full name: {{ full_name }}
Full name: John Doe

increment

Creates a new number variable with an initial value of 0 and increments it by 1 every time it is called. The increment tag creates a new variable with its own scope, separate from variables created with assign or capture.
{% increment variable_name %}
variable_name
string
The name of the variable to increment.
{% increment counter %}
{% increment counter %}
{% increment counter %}

Counter: {{ counter }}
0
1
2
Counter: 2

decrement

Creates a new number variable with an initial value of -1 and decrements it by 1 every time it is called. Like increment, the decrement tag creates a new variable with its own scope.
{% decrement variable_name %}
variable_name
string
The name of the variable to decrement.
{% decrement counter %}
{% decrement counter %}
{% decrement counter %}

Counter: {{ counter }}
-1
-2
-3
Counter: -3