Articles in this section

#and helper

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

  1. {{#and Contact.homeAddress zeroInteger}}true{{else}}false{{/and}}

  2. {{#and Contact.homeAddress emptyString}}true{{else}}false{{/and}}

  3. {{#and Contact.homeAddress emptyString}}true{{else}}false{{/and}}

  4. {{#and Contact.homeAddress emptyString}}true{{else}}false{{/and}}

  5. {{#and Contact.homeAddress emptyString}}true{{else}}false{{/and}}

{
  "Contact":{
    "homeAddress":"123 Anywhere",
    "offAddress":"789 Somewhere"
  },
  "emptyString":"",
  "nullfield":null,
  "zeroString":"0",
  "zeroInteger":0
}
  1. true

  2. false

  3. false

  4. true

  5. false

{{#and legends.unicorns legends.horses}} {{legends.unicorns}} - {{legends.horses}} {{else}} Not found {{/and}}

{
  "legends":{
    "unicorns":"11",
    "ponies":"22",
    "horses":"33",
    "total":"66"
  }
}

11-33

{{#and firstName lastName}} {{firstName}} {{middleName}} {{lastName}} {{else}}Not found {{/and}}

{
  "fullName":"Hillary Ann Swank",
  "firstName":"Hillary",
  "middleName":"Ann",
  "lastName":"Swank"
}

Hillary Ann Swank