什么! (感叹号)在 FreeMarker 中做什么?
What does the ! (exclamation point) in FreeMarker do?
我一直在 Magnolia code examples 的 FreeMarker 代码末尾看到感叹号。例如:
${content.header!}
感叹号叫什么,它有什么作用?
感叹号叫做default value operator。用于在插值(${...}
)returnsnull
时设置一个默认值。如果没有设置默认值,它 returns 一个空字符串 (""
)。
${content.header!}
<#-- Returns "" if content.header is null -->
${content.header!"Example Header"}
<#-- Returns "Example Header" if content.header is null -->
有关详细信息,请参阅 Dealing with missing variables。
我一直在 Magnolia code examples 的 FreeMarker 代码末尾看到感叹号。例如:
${content.header!}
感叹号叫什么,它有什么作用?
感叹号叫做default value operator。用于在插值(${...}
)returnsnull
时设置一个默认值。如果没有设置默认值,它 returns 一个空字符串 (""
)。
${content.header!}
<#-- Returns "" if content.header is null -->
${content.header!"Example Header"}
<#-- Returns "Example Header" if content.header is null -->
有关详细信息,请参阅 Dealing with missing variables。