iris.Django
The template engine's template parser provides methods to declare variables and use them in templateswith
. Throughwith
We can temporarily declare one or more variables for later use. In most cases, we would use it in conjunction with the include tag.
Example Code
{% with title="这是声明给header使用的title" keywords="这是声明给header使用的keywords" %} %}标题:{{title}},关键词:{{keywords}}。{% endwith %}
{% include "partial/header.html" with title="这是声明给header使用的title" keywords="这是声明给header使用的keywords" %}
with
Variables defined need to beendwith
enclosed in.
Additionallyiris.Django
also providesset
a way to declare variables, which can be used in the current template. For example:
{% 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