Hi guys, just trying to write a simple if statemen...
# general
m
Hi guys, just trying to write a simple if statement for my Invoice. Where have I gone wrong with my IF statement? <#if ${record.currency} = 'GBP'> 123 <#elseif ${record.currency} = 'Euro'> 456 <#elseif ${record.currency} = 'US Dollar'> 789 #else xyz <#/if>
k
there are no IF statements in NS. you should use CASE statement
s
There are if statements in xml templates, which this seems to be in.
🙌 1
s
Assuming that this is for an Advanced PDF or Email template, then you need to use a double equal signs:
<#if ${record.currency} == 'GBP'> 123 <#elseif ${record.currency} == 'Euro'> 456 <#elseif ${record.currency} == 'US Dollar'> 789 <#else> xyz <#/if>
🙏 1
m
Thanks @scottvonduhn - Used double equals signs as you advised, still still get the below error. Any other ideas? Thanks in advance! Syntax error in template "template" in line 196, column 31: You can't use "${" here as you are already in FreeMarker-expression-mode. Thus, instead of ${myExpression}, just write myExpression. (${...} is only needed where otherwise static text is expected, i.e, outside FreeMarker tags and ${...}-s.)
s
Ah, yes, inside the angle brackets you need to use the plain variables
<#if record.currency == 'GBP'> 123 <#elseif record.currency == 'Euro'> 456 <#elseif record.currency == 'US Dollar'> 789 <#else> xyz <#/if>
${record.currency}
only works outside of the
<#if>
tags
m
Thanks again @scottvonduhn! At least I know I wasn't million miles away. I now have an unclosed #if now, apparently. Although I have no idea where. Thanks again pal.
s
Sure. BTW, certain editors support the FreeMarker syntax and can help show you if anything is obviously off or if tags are out of balance. IntelliJ, VS Code and Notepad++ all support the syntax, either natively or with a plugin.
🙌 1
A regular XML editor won’t help much, since the #elseif tags won’t have a corresponding close tag
🙌 1