Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if-else in FreeMarker template

FreeMarker templates support an if-statement with the following syntax

<#if hot> 
  It's hot.
</#if>  

I've looked in the documentation and can't find any support for an if-else statement. Of course, I could achieve the same result with:

<#if hot> 
  It's hot.
</#if>  
<#if !hot> 
  It's not hot.
</#if>  

Is there support for if-else in FreeMarker?

like image 934
Dónal Avatar asked Nov 17 '08 19:11

Dónal


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 syntax is used to access data using FreeMarker under a condition?

To access them, you use the . variable_name syntax.

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.


2 Answers

Yes, you can write:

<#if hot>
it's hot
<#else>
it's not
</#if>

And if you're doing lots of freemarker, I really can recommend IntelliJ IDEA 8, its freemarker support really helps...

like image 101
Ulf Lindback Avatar answered Sep 22 '22 13:09

Ulf Lindback


Yes, the sintaxis is:

<#if condition>

...

<#elseif condition2>

...

<#elseif condition3>

...

<#else>

...

<#/if>

You can find Freemarker complete reference

If you are using Netbeans, there is this plugin

like image 23
iberck Avatar answered Sep 21 '22 13:09

iberck