Response Templating - Miscellaneous Helpers

This article describes some useful helpers that don’t neatly fit into any of the other categories.

Assignment

You can create a string variable of own using the assign helper, then use it later in your template e.g.:

{{#assign 'myCapitalisedQuery'}}{{capitalize request.query.search}}{{/assign}}

Capitalised query: {{myCapitalisedQuery}}

Size

The size helper returns the size of a string, list or map:

{{size 'abcde'}}               // Returns 5
{{size request.query.things}}  // Returns number of values in query param 'things'

With

The with helper creates a nested scope, allowing you to reference attributes on an object without fully qualifying it each time.

For instance, given a variable whose value is an object with the properties id and position, with allows these to be accessed without qualifying each time:

{{#with myObject}}
  ID: {{{id}}}
  Position: {{{position}}}
{{/with}}