Articles in this section

#with helper

The #with helper demonstrates how to pass a parameter to your helper. When a parameter calls a helper, it is invoked with whatever context the template passed in. This allows access to nested objects in the context without having to repeatedly type the parent name in each expression.

Template

{{#with library}}{{title}} on "{{album}}" by {{artist}} {{/with}}

Context

{
  "library": {
    "album": "The Sound",
    "title": "Danube Incident",
    "artist": "Lalo Schifrin"
  }
}

Output

Danube Incident on "The Sound" by Lalo Schifrin

The with helper passes a parameter to a helper.

{{#with field}} {{field1}} {{field2}} {{/with}}

When a parameter calls the helper, it invokes the context from the template.

Template

The author{{#with author}} {{firstName}} {{lastName}}{{/with}}

Context

{
  "title": "A Tale of Two Cities",
  "author": {
    "firstName": "Charles",
    "lastName": "Dickens"
  }
}

Output

Output The author Charles Dickens