{% var %}

Saves a value to the current scope for later reference. Optionally applies filters to the value before saving it.


{% var [name] = [value] [| filter1 [: arg [arg...]]] [| filter2 ...] %}

name: The name of the variable to save the value to. If name starts with '&', will attempt to assign the value by reference.

value: The value to assign to the new variable.

May optionally include one or more filters.

The var tag is superior to the assign and set tags in that it will always save the value on the current scope, thereby preventing the variable from being changed on any parent scopes. That is also the reason why you may choose not to use it.


Dynamically render html tags using var

{% var tagtype = "div" %} 〈{{tagtype}}〉 {% if true %} {% var tagtype = "span" %} 〈{{tagtype}}〉Some Content 〈/{{tagtype}}〉 {% endif %} 〈/{{tagtype}}〉

Var date assignment and date math

{% var minDate = "now" | midnight %} {% var maxDate = "now" | midnight | add_months: 1 %} {% calendar_entry_collection output_to_template start_date:minDate end_date:maxDate limit:30 sort_by:"start_date" sort_direction:"asc" %}