default

Usage

The | default filter returns the value passed as the argument if the filtered value is undefined or empty, otherwise the filtered value is returned.

{{ variable | default('The variable is not defined') }}

{# The above tag would be displayed as "The variable is not defined" #}

{% set variable = 'Variable is now defined' %}
{{ variable | default('The variable is not defined') }}

{# The above tag would now be displayed as "Variable is now defined" #}

You may also use this filter for method calls:

{{ object.getName(variable | default('Unknown')) }}
Copyright © 2024 Winter CMS
Edit on GitHub