aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/twig/twig/doc/tests/defined.rst
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twig/twig/doc/tests/defined.rst')
-rw-r--r--vendor/twig/twig/doc/tests/defined.rst30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/twig/twig/doc/tests/defined.rst b/vendor/twig/twig/doc/tests/defined.rst
new file mode 100644
index 00000000..702ce725
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/defined.rst
@@ -0,0 +1,30 @@
1``defined``
2===========
3
4``defined`` checks if a variable is defined in the current context. This is very
5useful if you use the ``strict_variables`` option:
6
7.. code-block:: jinja
8
9 {# defined works with variable names #}
10 {% if foo is defined %}
11 ...
12 {% endif %}
13
14 {# and attributes on variables names #}
15 {% if foo.bar is defined %}
16 ...
17 {% endif %}
18
19 {% if foo['bar'] is defined %}
20 ...
21 {% endif %}
22
23When using the ``defined`` test on an expression that uses variables in some
24method calls, be sure that they are all defined first:
25
26.. code-block:: jinja
27
28 {% if var is defined and foo.method(var) is defined %}
29 ...
30 {% endif %}