Variable Tags

Variable Tags are used to create new Liquid variables.

In this article:


assign

Creates a new variable.

{% assign x = 5 %} {% if x > 0 %} <p>Variables make things {{ x }} times more fun!</p> {% endif %} Use quotations ("") to save the variable as a string.

{% assign bird1 = "duck" %} {% assign bird2 = "red-legged honeycreeper" %} <p>Would you prefer a {{ bird1 }} or a {{ bird2 }}?</p>

capture

Captures the string inside of the opening and closing tags and assigns it to a variable. Variables created through {% capture %} are strings.

<p>Capture is a thief! He steals{% capture stolen_text %} my text{% endcapture %}!</p> <p>Capture says, "This is{{ stolen_text }} now!"</p>

increment

Creates a new number variable, and increases its value by one every time it is called. The initial value is 0.

<p>{% increment x %}</p> <p>{% increment x %}</p> <p>{% increment x %}</p> <p>{% increment x %}</p> <p>{% increment x %}</p> Variables created through the increment tag are independent from variables created through assign or capture.

decrement

Creates a new number variable, and decreases its value by one every time it is called. The initial value is -1.

<p>{% decrement x %}</p> <p>{% decrement x %}</p> <p>{% decrement x %}</p> <p>{% decrement x %}</p> <p>{% decrement x %}</p> Like increment, variables declared inside decrement are independent from variables created through assign or capture.

Contact support or access our 24/7 Live Chat:

Contact Support Live Chat

Need Help? Live Chat with Us.