if & else

Conditional statement to check if a value is defined or true.

1
2
3
4
5
6
7
8
9
{{if [value]}}
Hello!
{{/if}}
{{#if [value]}}
it's true or defined
{{else}}
it's false or undefined
{{/if}}
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