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?
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.
To access them, you use the . variable_name syntax.
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.
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...
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
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