What does the ! (exclamation point) in FreeMarker do?

I keep seeing exclamation points at the end of FreeMarker code in Magnolia code examples. For example:


What is the exclamation point called and what does it do?

1 answer

  • answered 2020-01-17 03:29 Ryan Brooke Payne

    The exclamation point is called a default value operator. It's used to set a default value to when an interpolation (${...}) returns null. If no default value is set, it returns and empty string ("").

    <#-- 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.