assign

assign is a Liquid tag to assign another name to a variable. It is a Liquid built-in tag.

Syntax

{% assign variable_name = variable|value %}

assign is followed by the name you want to give your new variable, an equals sign, and the value to assign to the new variable. This value can either be a literal value, like a text or number, or another variable.

Examples

{% assign title = "Test" %}
{{ title }}
 => Outputs "Test"

{% if user %}
  {% assign name = user.nickname %}
{% else %}
  {% assign name = "Anonymous" %}
{% endif %}
 => If the user is logged in, "name" now equals his nickname,
    else it is "Anonymous".

{% assign pi = 3 %}
 => "pi" will now equal 3!
page_revision: 4, last_edited: 1180550672|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.