I would like to check if a sequence is empty in a freemarker template.
This snippet works to check if a sequence contains a value:
<#if node.attachments?seq_contains("blue")> <pre>hello</pre> </#if>
However, if node.attachments
is empty i would like to do something else.
That is the syntax for this?
The has_content Function FreeMarker 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.
eval. This built-in evaluates a string as an FTL expression. For example "1+2"? eval returns the number 3. (To render a template that's stored in a string, use the interpret built-in instead.)
In the pursuit of comparison between FreeMarker , Thymeleaf, Groovy and Mustache, FreeMarker has the upper hand in performance. However, Thymeleaf wins the battle overall.
Comments: <#-- and --> Comments are similar to HTML comments, but they are delimited by <#-- and -->. Comments will be ignored by FreeMarker, and will not be written to the output.
Try:
<#if node.attachments?size != 0>
Or:
<#if node.attachments?has_content>
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