/Twig 1


The default filter returns the passed default value if the value is 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:

{{ var.method(foo|default('foo'))|default('foo') }}


Read the documentation for the defined and empty tests to learn more about their semantics.


  • default: The default value

© 2009–2017 by the Twig Team
Licensed under the three clause BSD license.
The Twig logo is © 2010–2017 SensioLabs