case
根据特定变量的值渲染特定表达式。
参数
variable{Any}输入值,必填firstValue{Any}枚举值,必填secondValue{Any}枚举值,选填returns{Any}
用法
{{#case variable }}
{{#when firstValue}}
firstExpression
{{/when }}
{{#when secondValue}}
secondExpression
{{else}}
thirdExpression
{{/when}}
{{/case}}
例子
{{#case product.type}}
{{#when 'Red'}}
it's is a red potion.
{{/when}}
{{#when 'Yellow'}}
it's is a yellow potion.
{{else}}
it's is a potion.
{{/when}}
{{/case}}
多个值
{{#case variable }}
{{#when firstValue second_value thirdValue}}
firstExpression
{{/when }}
{{#when fourthValue fifthValue sixthValue}}
secondExpression
{{else}}
thirdExpression
{{/when}}
{{/case}}
一个 when 标记可以接受多个值。如果提供了多个值,当变量与标签内的任何一个值相匹配时,表达式会被返回。以空格分隔的列表形式提供这些值。
{{#case product.tags}}
{{#when 'Love' 'Red'}}
it's a love or red potion.
{{/when}}
{{#when 'Yellow' 'Blue'}}
it's is a yellow or blue potion.
{{else}}
it's is a potion.
{{/when}}
{{/case}}
这篇文章对你有帮助吗?
SHOPLINE