1

Is there a better way to write this IF statement for testing multiple options of a variable?

<#if PRINTER_PET.RETAILER_NAME = 'BEST BUY' || PRINTER_PET.RETAILER_NAME = 'Best Buy Purchasing LLC'>
document 1 
<#elseif  PRINTER_PET.RETAILER_NAME = 'AMAZON' || PRINTER_PET.RETAILER_NAME = 'Amazon Fulfillment Services Inc Attn: Amazon.com' >
document 2
</#if>

Thank you, Erica

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

2 Answers2

2

You can extract PRINTER_PET.RETAILER_NAME into a variable, like <#assign retName = PRINTER_PET.RETAILER_NAME>, and then it's somewhat shorter (<#if retName == 'foo' || retName == 'bar'>, etc.). Also, if you have a lot of strings to compare with, <#if ['foo', 'bar', 'baaz']?seq_contains(retName)> might be nicer.

ddekany
  • 29,656
  • 4
  • 57
  • 64
  • ddekany, Thank you SO MUCH!!! That is what I was looking for. I was having a hard time figuring out how to do this via the documents online. Was getting the assign backwards...putting the variables in there instead of the data location. I ended up using your second IF <#if ['foo', 'bar', 'baaz']?seq_contains(retName)>. Thanks again, Erica – Erica Behnke Mar 19 '19 at 17:42
1

Follow Freemrker Comparison example and use == and ":

<#if PRINTER_PET.RETAILER_NAME == "BEST BUY" || PRINTER_PET.RETAILER_NAME == "Best Buy Purchasing LLC">
document 1 
<#elseif  PRINTER_PET.RETAILER_NAME == "AMAZON" || PRINTER_PET.RETAILER_NAME == "Amazon Fulfillment Services Inc Attn: Amazon.com" >
document 2
</#if>

The user == "Big Joe" expression in the <#if ...> will evaluate to the boolean true, so the above will say "It is Big Joe".

Logical or: ||

Ori Marko
  • 56,308
  • 23
  • 131
  • 233