mickthompson mickthompson - 3 months ago 19
Java Question

Freemarker 'Collection.contains' functionality

From my java code I'm returning a Set<String>. The view needs to check if the Set contains a specific string.. I can't find any docs on how Freemarker can handle this.

Any idea?

Answer

You can use seq_contains. You need FreeMarker 2.3.1

${x?seq_contains("blue")?string("yes", "no")}

This will output yes if the sequence contains "blue".

And from the comments, if you want this in an if statement

<#if x?seq_contains("myString")>

Here is the doco about it Built-ins for sequences