Variable
Variable tags enable you to create new Liquid variables.
Caution
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 named variable.
You can create variables of any basic type, object, or object property.
{% assign variable_name = value %}
variable_name
: The name of the variable being created.value
: The value you want to assign to the variable.
capture
Creates a new variable with a string value.
You can create complex strings with Liquid logic and variables.
{% capture variable %}
value
{% endcapture %}
variable
: The name of the variable being created.value
: The value you want to assign to the variable.
{% assign up_title = product.title | upcase %}
{% assign down_title = product.title | downcase %}
{% assign show_up_title = false %}
{% capture title1 %}
{% if show_up_title %}
Upcase title: {{ up_title }}
{% else %}
Downcase title: {{ down_title }}
{% endif %}
{% endcapture %}
{
"product": {
"title": "Boiler Jumpsuit"
}
}
Downcase title: boiler jumpsuit
decrement
Creates a new variable, with a default value of -1, that's decreased by 1 with each subsequent call.
Variables that are declared with decrement
are unique to the layout or section file that they're created in. However, the variable is shared across snippets included in the file.
Similarly, variables that are created with decrement
are independent of those created with assign and capture. However, decrement
and increment share variables.
{% decrement variable_name %}
variable_name
: The name of the variable is decremented.
{% decrement number %}
{% decrement number %}
{% decrement number %}
-1
-2
-3
increment
Creates a new variable, with a default value of 0, that's increased by 1 with each subsequent call.
Variables that are declared with increment are unique to the layout or section file that they're created in. However, the variable is shared across snippets included in the file.
Similarly, variables that are created with increment
are independent of those created with assign and capture. However, increment
and decrement share variables.
{% increment variable_name %}
variable_name
: The name of the variable is incremented.
{% increment variable %}
{% increment variable %}
{% increment variable %}
0
1
2
Updated over 1 year ago