Articles in this section

Nesting block helpers and raw blocks

The following expressions describe the expression format and samples for block helpers. Variables and “hard-coded” values may be nested and referenced.

Template

{{#if contact.phone}}{{contact.phone}}
{{else}} Phone number not found
{{/if}}

Context

{
  "contact": {
    "name": "Jack Parsons Laboratory",
    "phone": "310-555-1234"
  }
}

Output

310-555-1234

Block helpers may also be nested, as shown below.

Template

{{#compare customer1 "==" "2"}}
{{#compare customer2 "==" "5"}}
  True
{{else}}
  False
{{/compare}}{{else}}
  False
{{/compare}}

Context

{
  "customer1": "2",
  "customer2": "5"
}

Output

True

Raw blocks

Raw blocks are virtually the same as block helpers; however, child content is treated as a literal string.

Template

Context

Output

{{{{name}}}}
  {{Samantha}}
{{{{/name}}}}
{

}
{{Samantha}}