switch and case

The switch statement is used to perform different actions based on different conditions

1
2
3
4
5
6
7
8
9
10
11
{{#switch [value]}}
{{#case [compared_value] [compared_value]}}
Hello
{{/case}}
{{#case [compared_value] break=true}}
Hola
{{/case}}
{{#default}}
Bonjour
{{/default}}
{{/switch}}
Example
format JSON XML
Data JSON
1
2
3
4
5
6
7
{
"Product": {
"name": "Chocolate",
"size": "small",
"quantity":"8"
}
}
Code
1
2
3
4
5
{{#if Product.price}}
<div>Price: {{Product.price}}</div>
{{else}}
<div>Chocolate for free!</div>
{{/if}}
Result
Data XML
1
2
3
4
<Product
name="Chocolate"
size="small"
quantity="8" />
HTML
1
2
3
4
5
{{#if Product._price}}
<div>Price: {{Product._price}}</div>
{{else}}
<div>Chocolate for free!</div>
{{/if}}
Result