Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 514
Ryan Payne Avatar asked Jan 17 '20 03:01

Ryan Payne


1 Answers

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.

like image 195
Ryan Payne Avatar answered Oct 23 '22 14:10

Ryan Payne