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?
The has_content FunctionFreeMarker has built-in functions to detect for variables. The most common method of detecting for empty or null values uses the has_content function and the trim function. The has_content function is often used with another built-in FreeMarker function to detect for null values.
Apache FreeMarker™ is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data.
Note that FreeMarker does exact comparison, so string comparisons are case and white-space sensitive: "x" and "x " and "X" are not equal values.
Although FreeMarker has some programming capabilities, it is not a full-blown programming language like PHP. Instead, Java programs prepare the data to be displayed (like issue SQL queries), and FreeMarker just generates textual pages that display the prepared data using templates.
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
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