I have a template in which I do:
<#if result.numFound > 10>
(some data)
</#if>
This gives me parse error:
For "#if" condition: Expected a boolean, but this evaluated to a number
result.numFound
is Integer
.
I've read the documentation, maybe I'm missing something...
string (when used with a boolean value)Converts a boolean to a string. You can use it in two ways: As foo? string("yes", "no") : Formats the boolean value to the first parameter (here: "yes" ) if the boolean is true, and to the second parameter (here: "no" ) if it's false.
When applied to a boolean, the string built-in will act as a ternary operator. It's no very readable as this is not the intended usage of it. It's for formatting boolean values, like Registered: ${registered? string('yes', 'no')} .
c (when used with numerical value) This built-in converts a number to string for a "computer language" as opposed to for human audience. That is, it formats with the rules that programming languages used to use, which is independent of all the locale and number format settings of FreeMarker.
You missed that last couple of lines in the documentation :).
How to test if x is greater than 1? <#if x > 1> will be wrong, as FreeMarker will
interpret the first > as the end of the tag. Thus, either write <#if (x > 1)> or <#if x > 1>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With