Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 911
mickthompson Avatar asked Oct 28 '10 07:10

mickthompson


People also ask

Does FreeMarker have content?

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.

What is FreeMarker used for?

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.

Is FreeMarker case sensitive?

Note that FreeMarker does exact comparison, so string comparisons are case and white-space sensitive: "x" and "x " and "X" are not equal values.

Is FreeMarker a programming language?

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.


1 Answers

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

like image 97
Iain Avatar answered Oct 22 '22 15:10

Iain