mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-04 22:47:21 +00:00
added notes in the doc about how the defined test and the default filter work
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
Reference in New Issue
Block a user