case
Render specific content based on the value of a variable.
Params
variable{Any}The input value. required.firstValue{Any}Enumerated value. required.secondValue{Any}Enumerated value. optional.returns{Any}
Usage
{{#case variable }}
{{#when firstValue}}
firstExpression
{{/when }}
{{#when secondValue}}
secondExpression
{{else}}
thirdExpression
{{/when}}
{{/case}}
Examples
{{#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}}
Multiple values
{{#case variable }}
{{#when firstValue second_value thirdValue}}
firstExpression
{{/when }}
{{#when fourthValue fifthValue sixthValue}}
secondExpression
{{else}}
thirdExpression
{{/when}}
{{/case}}
A when can identify multiple values in a list format separated by spaces. If multiple values are provided, the corresponding content is returned when the variable matches any value within the list.
{{#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}}
Was this article helpful to you?