Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

freemarker templates check if sequence is empty

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?

like image 520
SeanPlusPlus Avatar asked Jan 16 '15 20:01

SeanPlusPlus


People also ask

How do I check if a template is null in FreeMarker?

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.

What is eval in FreeMarker?

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.)

Which is better Thymeleaf or FreeMarker?

In the pursuit of comparison between FreeMarker , Thymeleaf, Groovy and Mustache, FreeMarker has the upper hand in performance. However, Thymeleaf wins the battle overall.

How do I comment in FreeMarker template?

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.


1 Answers

Try:

<#if node.attachments?size != 0> 

Or:

<#if node.attachments?has_content> 
like image 91
Zipper Avatar answered Sep 28 '22 09:09

Zipper