Testing a Boolean Type Variable in Freemarker

The isOffline field in my websetting is Boolean. In my Freemarker template, I need to check if this is true for false.

So, I did the following, but it does not work

 <#if !websetting.isOffline> false </#if> 

It seems that Freemarker does not support Not ! . I also tried <#if websetting.isOffline == false> false </#if> but it does not work.

+6
source share
1 answer

isOffline not the best name for a boolean because the getter method also has isOffline .

If you cannot change the name of the property, then show that you want to call the method in the template with () .

 <#if !websetting.isOffline()> false </#if> 

But it’s better to change the name to something w / o is in front of it (for example, offline ). Then you can use it in the template.

 <#if !websetting.offline> false </#if> 
+6
source

Source: https://habr.com/ru/post/971119/


All Articles