if-else in FreeMarker template
Solution 1
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...
Solution 2
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
Dónal
I earn a living by editing text files. I can be contacted at: [email protected] You can find out about all the different kinds of text files I've edited at: My StackOverflow Careers profile
Updated on May 23, 2020Comments
-
Dónal about 4 years
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?
-
Ulf Lindback over 15 yearsGo to the document iberk pointed out, search for if on that page and you get to: freemarker.sourceforge.net/docs/ref_directive_if.html
-
Adrien Be over 11 yearsThanks. Works with this syntax too [#if myVar?has_content && myVar==<someValue>] ... [#elseif myVar?has_content && myVar==<someValue>] ... [#else] ... [/#if]