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?
Asked
Active
Viewed 2.4k times
16

mickthompson
- 5,442
- 11
- 47
- 59
1 Answers
36
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

Iain
- 10,814
- 3
- 36
- 31
-
1I think the answer could be corrected to have `<#if mySet?seq_contains("myString")>` because there was not specified that printing a string is required Also just `<#if x.contains("myString")>` should work – skrii Jul 11 '16 at 14:20
-
1I've added the if example. The point of the first example is to make it clear what `seq_contains` does, I wasn't trying to show all the various statements in which you can use it. – Iain Aug 14 '16 at 00:24