assign
The assign tag is a native feature of Liquid. In Mechanic-flavored Liquid, the assign tag is extended to support assigning within arrays and hashes.
Assignment into arrays and hashes is always by value, never by reference.
Assigning into arrays
Arrays support assignment by index, using integer lookups.
{% assign x = array %}
{% assign x[0] = "one" %}
{% assign x[x.size] = "two" %}
{% assign the_third_zero_based_index = 2 %}
{% assign x[the_third_zero_based_index] = "three" %}
{{ x | json }}
Assigning into hashes
Hashes support assignment by key, using string lookups.
{% assign x = hash %}
{% assign x["one"] = 1 %}
{% assign x["two"] = 2 %}
{% assign three = "three" %}
{% assign x[three] = 3 %}
{{ x | json }}
Last updated
Was this helpful?