General tags - Define variable assignment tags

iris.DjangoThe template resolver of the template engine provides methods that can be declared and used in a template.with. passwithWe can temporarily declare single or multiple variables for subsequent use. In most cases, we will use it with the include tag.


Sample code


{% with title="这是声明给header使用的title" keywords="这是声明给header使用的keywords" %} %}标题:{{title}},关键词:{{keywords}}。{% endwith %}
{% include "partial/header.html" with title="这是声明给header使用的title" keywords="这是声明给header使用的keywords" %}

withThe defined variable needs to be usedendwithCome to wrap.

in additioniris.DjangoAlso providedset, the variable can be declared in the current template. like:


{% set new_var = "hello" %}{{ new_var }}
{% block content %}{% set new_var = "world" %}{{ new_var }}{% endblock %}
{{ new_var }}{% for item in simple.misc_list %}
{% set new_var = item %}{{ new_var }}{% endfor %}
{{ new_var }}
{% set car=someUndefinedVar %}{{ car.Drive }}No Panic