Response Templating - Miscellaneous Helpers
Other assorted useful 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.:
Val helper
The val
helper can be used to access values or provide a default if the value is not present. It can also be used to
assign a value to a variable much like the assign
helper. The main difference between val
and assign
is that val
will maintain the type of the date being assigned whereas assign
will always assign a string.
Size
The size
helper returns the size of a string, list or map:
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:
Range
The range
helper emits an array of integers between the bounds specified in the
first and second parameters (both of which are mandatory).
As mentioned above, you can use this with randomInt
and each
to output random length, repeating pieces of content e.g.
Array
The array
helper emits an array containing exactly the values specified as parameters.
Passing no parameters will result in an empty array being returned.
Array add & remove helpers
The arrayAdd
and arrayRemove
helpers can be used to add or remove elements from an array based on a position value
or the start
or end
keywords. If no position is specified, the element will be added or removed from the end of the
array.
arrayJoin helper
The arrayJoin
helper will concatenate the values passed to it with the separator specified:
You can also specify a prefix
and suffix
to be added to the start and end of the result:
The arrayJoin
helper can also be used as a block helper: