是否有更好的方法来编写此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>
谢谢Erica
你可以将PRINTER_PET.RETAILER_NAME
提取到一个变量中,比如<#assign retName = PRINTER_PET.RETAILER_NAME>
,然后它会更短(<#if retName == 'foo' || retName == 'bar'>
等)。另外,如果你有很多字符串要比较,<#if ['foo', 'bar', 'baaz']?seq_contains(retName)>
可能会更好。
关注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
,因此上面将说“它是大乔”。逻辑或:||