Skip to main content

default

Function default 

Source
pub fn default(
    state: &State<'_, '_>,
    value: &Value,
    args: Rest<Value>,
) -> Result<Value, Error>
Expand description

If the value is undefined it will return the passed default value, otherwise the value of the variable:

<p>{{ my_variable|default("my_variable was not defined") }}</p>

Setting the optional second parameter to true will also treat falsy values as undefined, e.g. empty strings:

<p>{{ ""|default("string was empty", true) }}</p>