The #and block helper renders the expression if both of the specified parameters are true (according to JavaScript rules). If the result is false, the {{else}} expression prints in the output. If the field is undefined, null, or an empty string, it will evaluate as false, otherwise it will be true. The integer value of 0 will evaluate to false; however, the STRING value of "0" evaluates to true, as all non-empty strings are true:
{{#and field field}} expr {{else}} expr {{/and}}
|
Template |
Context |
Output |
|---|---|---|
|
{
"Contact":{
"homeAddress":"123 Anywhere",
"offAddress":"789 Somewhere"
},
"emptyString":"",
"nullfield":null,
"zeroString":"0",
"zeroInteger":0
}
|
|
|
|
{
"legends":{
"unicorns":"11",
"ponies":"22",
"horses":"33",
"total":"66"
}
}
|
11-33 |
|
|
{
"fullName":"Hillary Ann Swank",
"firstName":"Hillary",
"middleName":"Ann",
"lastName":"Swank"
}
|
Hillary Ann Swank |