{% set %}

Overwrites the value saved on the given variable in the nearest scope. If the variable is not saved on any scopes, saves the value to the root scope. Optionally applies filters to the value before saving it.

Syntax

{% set [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 set tag should ideally be used to update the value saved in a variable on a parent scope. It will only create a new varaible if the variable name provided has not been set on any available scope. This makes it ideal for use along with the var tag.

Examples

Set

Copy
{% var query = "movein_ready = true" %} {% if request.query_params has_key beds %} {% set query = query | append: " and beds = " | append: request.query_params.beds %} {% endif %} {% if request.query_params.has_key baths %} {% set query = query | append: " and baths = " | append: request.query_params.baths %} {% endif %} {% datastore_item_collection collection datastore:entity query:query %}