General label - Variable definition and assignment label

iris.DjangoThe template engine's template parser provides methods to declare variables and use them in templateswith. ThroughwithWe can temporarily declare one or more variables for subsequent use. In most cases, we will 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" %}

withThe defined variables need to be usedendwithwrap.

otherwiseiris.Djangoalso providessetthe way to declare a variable, 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