Create new variables in templates
Sometimes you want to create a temporal variable to store something or do anything you want with it, problem is that django template system doesn't provide this kind of feature. This template tag is just for that. Syntax:: {% assign [name] [value] %} This will create a context variable named [name] with a value of [value] [name] can be any identifier and [value] can be anything. If [value] is a callable, it will be called first and the returning result will be assigned to [name]. [value] can even be filtered. Example:: {% assign count 0 %} {% assign str "an string" %} {% assign number 10 %} {% assign list entry.get_related %} {% assign other_str "another"|capfirst %} {% ifequal count 0 %} ... {% endifequal %} {% ifequal str "an string" %} ... {% endifequal %} {% if list %} {% for item in list %} ... {% endfor %} {% endif %}
- template
- variable
- assign