default

The default filter returns the passed default value if the variable is undefined or empty, otherwise, it returns the variable value.

{{ variable|default('My Default Value') }}

{{ item.name|default('Default item name') }}

{{ post.image.tag|default('No image set') }}

{{ product['manufacturer']|default('Nobody manufactures this product') }}

{{ ''|default('The passed variable is empty') }}

It is a good idea to use the default filter if you are using a variable in a place where it must have a value.

{% do redirect(urlToGoTo|default('/default-page')) %}

< Back to the list of filters