Update default.rst

Add warning for potentially confusing behaviour and alternative solution.
This commit is contained in:
Nicolas Sauveur
2020-02-24 15:27:08 +01:00
committed by Fabien Potencier
parent 8de0b772dc
commit 9ff9a4d3c0
+9
View File
@@ -21,6 +21,15 @@ undefined:
.. code-block:: twig
{{ var.method(foo|default('foo'))|default('foo') }}
Using the ``default`` filter on a boolean variable might trigger unexpected behaviour, as
``false`` is treated as an empty value. Consider using ``??`` instead:
.. code-block:: twig
{% set foo = false %}
{{ foo|default(true) }} {# true #}
{{ foo ?? true }} {# false #}
.. note::