Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check null and empty both in freemarker string?

Tags:

freemarker

For example. String s can have these values like "value", "" or null.

<#if str?? && str?has_content>
    ${str}
</#if>

Can I check ??(null) and ?has_content(empty not null) both value in freemarker if statement not using TemplateModel?

like image 536
Dongin Min Avatar asked Oct 16 '18 05:10

Dongin Min


1 Answers

str?has_content returns true if str is non-null (non-missing), and is also not a 0-length string. So you just need <#if str?has_content>.

(As of TemplateModel-s, every value is a TemplateModel as far as templates see. There's no such thing as a non-TemplateModel value.)

like image 121
ddekany Avatar answered Oct 23 '22 19:10

ddekany