iris.Django
The template resolver of the template engine provides methods that can be declared and used in a template.with
. passwith
We 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" %}
with
The defined variable needs to be usedendwith
Come to wrap.
in additioniris.Django
Also 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