Freemarker function with parameter that can be empty
Here's what I did, which seems to work in most scenarios:
The default value should be an empty string, and the null-check should be ?has_content.
<#function someFunction optionalParam="" >
<#if (optionalParam?has_content)>
<#-- NOT NULL -->
<#else>
<#-- NULL -->
</#if>
</#function>
In the end I did it like this:
<#function formatDate anyDate='notSet'> <#assign dateFormat = read_from_configuration() /> <#if anyDate?is_date> <#return anyDate?string(dateFormat) /> <#else > <#return '' /> </#if> </#function>