Ryan Payne
Ryan Payne

Reputation: 6331

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:

${content.header!}

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

Upvotes: 15

Views: 6696

Answers (1)

Ryan Payne
Ryan Payne

Reputation: 6331

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.

Upvotes: 22

Related Questions