Jinja has a built in default filter that can be used to set a default value when one isn’t provided.
default(value, default_value=u’’, boolean=False)
If the value isn’t defined, default
will display what’s in the default_value
field. Passing in a true
as the second parameter will return the default value if the value is defined but blank.
One of the most common use cases is to use the default value for a customer’s name:
Remember that Jinja can be used in any part of the template: HTML, CSS, Plain Text, Subject Line, Preheader. This can be useful for setting default styles in a snippet.
It’s also useful for setting a default loop control: