Freemarker 'Collection.contains' functionality

mickthompson picture mickthompson · Oct 28, 2010 · Viewed 16.3k times · Source

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

Iain picture Iain · Oct 28, 2010

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