Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FreeMarker: Expected a boolean, but this evaluated to a number

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...

like image 640
ex3v Avatar asked Feb 17 '14 10:02

ex3v


People also ask

How do you convert boolean to string in FreeMarker?

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.

How do you use the ternary operator in FreeMarker?

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')} .

What is C in FreeMarker?

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.


1 Answers

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 &gt; 1>.
like image 131
Miichi Avatar answered Oct 24 '22 22:10

Miichi