是否有更好的方式编写此IF语句来测试变量的多个选项?
<#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>
谢谢你, 埃里卡
答案 0 :(得分:2)
您可以将PRINTER_PET.RETAILER_NAME
提取到变量中,例如<#assign retName = PRINTER_PET.RETAILER_NAME>
,然后变短一些(<#if retName == 'foo' || retName == 'bar'>
等)。另外,如果您有很多字符串要比较,<#if ['foo', 'bar', 'baaz']?seq_contains(retName)>
可能会更好。
答案 1 :(得分:1)
遵循Freemrker Comparison示例,并使用==
和"
:
<#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>
user == "Big Joe"
中的<#if ...>
表达式将计算为布尔值true
,因此上面将说“ It is Big Joe”。逻辑或:||