Here’s my testMacro.txt
<#macro myMacro value1 value2>
<#list 1..value1 as x>
<#if x=value1>
<#switch value2>
<#case value2 = 1>
CASE1
<#break>
<#case value2 =2 >
CASE2
<#break>
<#case value2 = 3>
CASE3
<#break>
</#switch>
<#else>
ELSE
</#if>
</#list>
<@myMacro value1=3 value2=1 />
Here is the Exception that I am getting.
Exception in thread "main" java.lang.RuntimeException: freemarker.template.TemplateException: The only legal comparisons are between two numbers, two strings, or two dates.
Left hand operand is a freemarker.template.SimpleNumber
Right hand operand is a freemarker.template.TemplateBooleanModel$2
Now this is in the switch case statement, though line number is not given in the exception, but I commented the switch statement and there was no exception, hence I am concluding that its some problem with the case statement.
Kindly help.
For historical reasons
=is an alias of==, except on places where an assignment is expected. So'<#case value2 = 1>'is'<#case value2 == 1>', and thus it ends up being'<#case true>'or'<#case false>', hence the error message. So as you have figured, it should be'<#case 1>'and such, just like in C-ish languages. As of the last example in the Manual, that example is wrong…