Skip to content
Browse files

added notes in the doc about how the defined test and the default fil…

…ter work
  • Loading branch information...
1 parent c001264 commit 88dd4ac5797a4ffe702a5eb5a0e5f5f5bea187bf @fabpot fabpot committed
Showing with 18 additions and 0 deletions.
  1. +9 −0 doc/filters/default.rst
  2. +9 −0 doc/tests/defined.rst
View
9 doc/filters/default.rst
@@ -9,10 +9,19 @@ undefined or empty, otherwise the value of the variable:
{{ var|default('var is not defined') }}
{{ var.foo|default('foo item on var is not defined') }}
+
{{ var['foo']|default('foo item on var is not defined') }}
{{ ''|default('passed var is empty') }}
+When using the ``default`` filter on an expression that uses variables in some
+method calls, be sure to use the ``default`` filter whenever a variable can be
+undefined:
+
+.. code-block:: jinja
+
+ {{ var.method(foo|default('foo'))|default('foo') }}
+
.. note::
Read the documentation for the :doc:`defined<../tests/defined>` and
View
9 doc/tests/defined.rst
@@ -19,3 +19,12 @@ useful if you use the ``strict_variables`` option:
{% if foo['bar'] is defined %}
...
{% endif %}
+
+When using the ``defined`` test on an expression that uses variables in some
+method calls, be sure that they are all defined first:
+
+.. code-block:: jinja
+
+ {% if var is defined and foo.method(var) is defined %}
+ ...
+ {% endif %}

0 comments on commit 88dd4ac

Please sign in to comment.
Something went wrong with that request. Please try again.