Home > front end >  How to use a method that returns boolean in ftl's <#if> statement
How to use a method that returns boolean in ftl's <#if> statement

Time:05-25

So, in Java, you can call some methods that return Boolean on a String, for example, string.startsWith("substring"). I want to use this in the ftl file, but for some reason this does not work.

<#if string.startsWith("substring")></#if>

I am pretty new to ftl, I just started learning it today, but, why this does not work? In java, if statement accepts Boolean, startsWith method returns Boolean, so, what is the problem here?

Error is: Expected a hash, but this has evaluated to a string. I do not get it, how can if statement receive a hash?? Should not it receive a Boolean?

CodePudding user response:

Most Java String methods are hidden in FTL. You have to instead use an FTL builtin. In your case, use

<#if string?starts_with("substring")></#if>

See documentation

  • Related