I keep seeing exclamation points at the end of FreeMarker code in Magnolia code examples. For example:
${content.header!}
What is the exclamation point called and what does it do?
The exclamation point is called a default value operator. It's used to set a default value when an interpolation (${...}
) returns null
. If no default value is set, it returns an empty string (""
).
${content.header!}
<#-- Returns "" if content.header is null -->
${content.header!"Example Header"}
<#-- Returns "Example Header" if content.header is null -->
See Dealing with missing variables for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With