What is the most elegant what of comparing numbers in freemarker?
<#if (variable = 2) ></#if>
This will not include a null check?
If I do this
<#if (variable! = 2) ></#if>
Then freemarker will complain about different types.
I ended up doing this
<#if (variable!?html = "2") ></#if>
But I guess this is not the way of doing it? How do I compare numbers with a null check in freemarker?
What do you want to happen if the variable is null? If you want then false:
If you want to assume 0:
Notes:
=also works, but is a bad practice, as the expression can be confused with named parameter assignment. The()is redundant; it’s not like in Java.?htmlmeant to be used escaping<and such, but worse, you trigger localized formatting there that can spoil the comparison. So if you ever want to do something like that, use?c(*c*omputer formatting) instead.