mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-08 00:17:29 +00:00
Update default.rst
Add warning for potentially confusing behaviour and alternative solution.
This commit is contained in:
committed by
Fabien Potencier
parent
8de0b772dc
commit
9ff9a4d3c0
@@ -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::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user