Handlebars helpers can be used to implement functionality that is not part of the handlebars language itself. The following list of helpers is supported by integrator.io:
Custom helpers | Block helpers | @Data variables | |
---|---|---|---|
For a downloadable guide, see Handlebars helper reference (PDF format).
Custom Helpers
add
Adds all of the specified variables. This helper adds JSON variables, “hard-coded” values, or a combination thereof. Absolute values do not require context JSON variables. The example below only shows integers, but it also works with floats and decimals.
{{add field field}}
Template | Context | Output |
---|---|---|
{{add item1 item2 item3}} |
{ |
144 |
{{add "2" "5" "2"}} |
9 |
|
{{add item1 "2" "3" item3}} |
138 |
avg
Computes the average of the specified values. This helper will average variables, “hard-coded” values, or a combination thereof. Absolute values do not require Context JSON variables.
{{avg field}}
Template | Context | Output |
---|---|---|
{{avg item1 item2 item3}} |
{ |
48 |
{{avg "2" "5" "2"}} |
3 |
|
{{avg item1 "2" "3" item3}} |
34.5 |
base64Decode
Decodes any Base64 string to the specified encoding format.
base64String
The first argument (required) is a Base64 string.
decodeFormat
The second argument (optional) is the encoding format to which the string will be decoded. If the second argument is not provided, the string decodes in UTF8 format. This arugment supports the following formats:
- "ascii"
- "base64"
- "hex"
- "ucs2" or "ucs-2"
- "utf16le" or "utf-16le"
- "utf8" or "utf-8" – default
- "binary"
- "latin1"
{{base64Decode base64String decodeFormat}}
Template | Context | Output |
{{base64Decode str}} |
str = 'SGVsbG8gV29ybGQhIQ==' |
Hello World!! |
{{base64Decode str "utf8"}} |
||
{{base64Decode null}} |
' ' |
|
{{base64Decode undefined}} |
||
{{base64Decode str "ascii"}} |
Hello World!! |
|
{{base64Decode str "binary"}} |
||
{{base64Decode str "hex"}} |
48656c6c6f20576f726c642121 |
|
{{base64Decode str str "utf8"}} |
Error: handlebars Helper {{base64Decode}} expects maximum 2 arguments only. |
|
{{base64Decode str |
Error: wrongEncodingFormat encoding format is not supported. |
base64Encode
Concatenates and encodes all the passed arguments to the Base64 encoding format.
Note: Use triple-curly braces for this expression.
{{{base64Encode field}}}
Template | Context | Output |
---|---|---|
{{{base64Encode userName}}} |
{ |
dXNlcm5hbWU= |
{{{base64Encode userName pwd}}} |
dXNlcm5hbWVwYXNzd29yZA== |
|
{{{base64Encode userName ":" pwd}}} |
dXNlcm5hbWU6cGFzc3dvcmQ= |
capitalize
Capitalizes the first letter of the first word in a string.
{{capitalize field}}
Template | Context | Output |
---|---|---|
The {{capitalize type}} is a |
{ |
The Dog is a |
{{capitalize day}} |
{ |
This is the day! |
capitalizeAll
Capitalizes the first letter of all the words in a string.
{{capitalizeAll field}}
Template |
On this day, the {{capitalizeAll type}} . . . |
---|---|
Context |
{ |
Output |
On this day, the Dog, Wolf, Extant Grey Wolf . . . |
ceil
Returns the smallest integral value that is greater than or equal to the specified value. In short, ceil rounds the value up to the nearest whole number.
{{ceil field}}
Template | Context | Output |
---|---|---|
{{ceil item1}} |
{ |
46 |
compare
The compare helper compares data variables against each other using logical operators. The "else" statement is used to output text if the argument returns a false condition.
{{#compare field operator field}} expr {{else}} expr {{/compare}}
Template |
{{#compare details.fromState "===" "NE"}}+{{details.qty}} |
---|---|
Context |
{ |
Output |
+3 |
This example shows a comparison of the quantity on hand against the quantity ordered, and logical output.
Template |
{{#compare qty ">=" ordered}}Please ship {{qty}} units |
---|---|
Context |
{ |
Output |
Please ship 100 units |
This example uses compare to verify a phone number field has exactly 10 digits. If not, the output is ten zeros (0000000000).
Template |
{{#compare phone.length "===" 10}}{{else}}0000000000{{/compare}} |
---|---|
Context |
{ |
Output |
0000000000 |
dateAdd
Adds or subtracts the specified offset value from the specified date and returns the result in the specified time zone.
{{dateAdd dateField offsetField timeZoneField}}
Each of these fields is discussed in further detail below.
Note: not all of the fields in the default expression need to be present, as shown in the some of the examples. See also: dateFormat and timeStamp.
In this example, the timeZoneField is set to New York and the offsetField is shifted one day ahead (in milliseconds.) This will render the date one day ahead of what is in the Context. New York is -5:00 UTC, as shown in the output.
Template |
{{dateAdd dateOrders "107280000" "America/New_York"}} |
---|---|
Context |
{ |
Output |
2019-12-15T00:48:00-05:00 |
dateField
{{dateAdd dateField offsetField timeZoneField}}
In the first example below, the offset and timeZone fields have been removed and only the referenced object name:value pair in the Context file will be passed to the output. The Second example shows the offsetField set to one day behind, and is reflected in the output. The third example shows the timeZone Field entered with no offset entered. The fourth example shows a complete expression with the date set to one day ahead.
Template | Context | Output |
---|---|---|
{{dateAdd dateOrders}} |
{ |
2019-11-05T15:25:00.000Z |
{{dateAdd dateOrders "-86400000"}} |
2019-11-04T15:25:00.000Z |
|
{{dateAdd dateOrders "" "America/Los_Angeles"}} |
2019-11-05T07:25:00-08:00 |
|
{{dateAdd dateOrders "86400000" "America/Los_Angeles"}} |
2019-11-06T07:25:00-08:00 |
You can also enter a fixed date value in quotes:
{{dateAdd "Mon Nov 21 2019 20:08:40 GMT+0000"}}
Or you can add a standard date and the system will automatically format the output to ISO specification:
{{dateAdd "Nov 21, 2019"}} will output: 2019-11-21T00:00:00.000Z
offsetField
This field allows the date to be set to a hard-coded string.
{{dateAdd dateField offsetField timeZoneField}}
Time values are expressed in milliseconds
- “86400000” = one day ahead (86,400,000 ms);
- "107280000"= two days ahead (107,280,000 ms);
- “-86400000” = one day behind (-86,400,000);
- Calculate milliseconds here
- Scientific notation may also be used: “1E6” = 1M (10^6 or 1,000,000 ms).
Template | Context | Output |
---|---|---|
{{dateAdd dateOrders "86400000"}} |
{ |
2019-12-15T00:00:00.000Z |
{{dateAdd dateOrders "172800000"}} |
2019-12-16T00:00:00.000Z |
|
{{dateAdd dateOrders "-86400000"}} |
2019-12-13T00:00:00.000Z |
Setting the date using offsetField
- The date offset in the first template is set to “86400000” (one day) and the output reflects the date as one day ahead of the dateOrders field in the Context; doubling this number will place the date two days ahead of the date in the value;
- The second example has the original offsetField value doubled “172800000” (two days);
- Conversely, placing a minus sign before the numeric value “-86400000” will subtract oneday from the date.
timeZoneField
This field uses standard ISO string date format where the offset value is subtracted from the specified date along with time zone. See the next section for more details on this setting.
{{dateAdd dateField offsetField timeZoneField}}
Here, the offsetField is set to null “ ” which will output the time in Hong Kong local time which is +8 UTC.
{{dateAdd dateField "" "Asia/Hong_Kong"}}
Template |
{{dateAdd dateOrders "" "Asia/Hong_Kong"}} |
---|---|
Context |
{ |
Output |
2019-12-14T08:00:00+08:00 |
The following examples show the conversion to UTC/GMT/Zulu time. Note that New York is -5 and Hong Kong is +8.
Template | Context | Output |
---|---|---|
{{dateAdd dateOrders " "}} |
{ |
2019-11-05T15:25:00.000Z |
{{dateAdd dateOrders "" "America/New_York"}} |
019-11-05T10:25:00-05:00 |
|
{{dateAdd dateOrders "" "Asia/Hong_Kong"}} |
2019-11-05T23:25:00+08:00 |
dateFormat
This helper allows the adjustment and transformation of time and date fields to be output in a particular format and altered according to your needs. The date and time fields are not all required in an expression, and they can be used in a modular fashion.
{{dateFormat o/pformat date i/pformat timezone}}
For current UTC and world time zones, see Time.gov.
The default date conforms to ISO specification:
- Structure: YYYY-MM-DD[T]hh:mm:ss.sss[Z]
- Output: 2019-11-12T21:02:32+00:00
- The date above is Nov 12, 2019, 1:02:32 PM PDT= 9:02:32 PM UTC
Time and date format codes:
- YYYY: four-digit year
- MM : two-digit month (01=January, etc.)
- DD : two-digit day of month (01 through 31)
- [T]: Time displayed as Coordinated Universal Time (UTC)
- HH: two digit hours (00 through 23)
- hh : two digit hours (01 through 12) Note: Use with a (am/pm) or A (AM/PM).
- mm: two digit minutes (00 through 59)
- ss : two digit seconds (00 through 59)
- SSS: one or more digits representing a decimal fraction of a second
- [Z]: expressed in Handlebars as "Zulu Time". If Z is present at the end of the date field, the time at this point will be expressed as Zulu time: +00:00
- a: am or pm
- A: AM or PM
For a complete list of all available time and date format codes, see Time and date format codes.
o/pformat
This field allows you to define the time and date format in the template which will be output accordingly. This field also works in concert with the "i/p format" field, which is discussed in further detail below.
{{dateFormat o/pformat date i/pformat timezone}}
Note: All date formats are placed in double quotation marks.
- “MM-DD-YYYY” = 01-01-2020
- “MM/DD/YYYY” = 01/01/2020
- “YYYY.DD.MM” = 2020.31.01
Template |
{{dateFormat "MM-DD-YYYY hh:mm" dateOrders "YYYY-DD-MM hh:mm"}} |
---|---|
Context |
{ |
Output |
05-25-1966 10:36 |
date
This field passes the current date to the output unless specified in the context file. The following example shows how to print the current date in the format specified in the o/pformat field in the template.
Template | Context | Output |
---|---|---|
{{dateFormat "MM-DD-YYYY" date}} |
{ |
02-26-2020 |
i/pformat
This field is the date object referenced in the Context. It can be hard-coded directly in the expression:
{{dateFormat o/pformat date i/pformat timezone}}
o/pformat vs. i/pformat:
- Output format (o/pformat) is where you define the desired output format
- Input format (i/pformat) is where you define the "input" format contained in the Context file
In the example below, the JSON Context format is "year/day/month" (1966/25/05). To output the date in the standard US format, define this format in the "o/pformat" field, as shown.
Template |
{{dateFormat "MM-DD-YYYY hh:mm" dateOrders "YYYY-DD-MM hh:mm"}} |
---|---|
Context |
{ |
Output |
05-25-1966 10:36 |
timezone
This fields utilizes standard ISO string date format where the offset value is subtracted from the specified date along with time zone.
{{dateFormat o/pformat date i/pformat timezone}}
In the example below, note the "Z" in the o/p format field? this is telling the system to output the timezone assigned in the "timezone" field and adjust the time automatically for the chosen timezone-Los Angeles.
Template |
{{dateFormat "MM-DD-YYYY hh:mmZ" dateOrders "YYYY-DD-MM hh:mm" "America/Los_Angeles"}} |
---|---|
Context |
{ |
Output |
05-25-1966 03:36-07:00 |
decodeURI
Decodes the specified URI. This example decodes the sample dataset from the “encodeURI” example.
{{{decodeURI field}}}
Note: This expression uses three curly braces.
Template |
{{{decodeURI orders}}} |
---|---|
Context |
{ |
Output |
overseas order flow |
The URI may also be a “hard-coded” value declared in the expression.
Template |
{{{decodeURI "overseas%20order%20flow"}}} |
---|---|
Context |
{ |
Output |
overseas order flow |
If you do not want the parameters inside the placeholder to be encoded (called escaping), use three brackets {{{ }}} - especially, when you intend to perform an encode/decode operation on the strings provided in the argument list (e.g. base64Encode or decodeURI).
HTML Encoded |
{{placeholder}} |
---|---|
HTML and URL Encoded |
{{encodeURI field}} |
URL Encoded |
{{{encodeURI field}}} |
No Encoding Applied |
{{{ placeholder }}} |
divide
Returns the resultant quotient of two specified values. This helper returns the quotient of two variables, “hard-coded” values, or a combination thereof. Absolute values do not require context JSON variables.
{{divide field}}
Template | Context | Output |
---|---|---|
{{divide item1 item2}} |
{ |
3 |
{{divide 2002 100}} |
20.02 |
|
{{divide item1 3}} |
11 |
encodeURI
This helper expression encodes the specified uniform resource indicator (URI), enclosed in three curly braces.
{{{encodeURI field}}}
Certain characters are used to encode and are not allowed in the source value:
, / ? : @ & = + $ #
Tip: Call decodeURI to decode a previously encoded URI.
Template |
{{{encodeURI orders}}} |
---|---|
Context |
{ |
Output |
overseas%20order%20flow |
The value may also be declared as a “hard-coded” in the expression with the same output:
{{encodeURI "sample data type"}}
floor
This helper is the inverse of ceil. Floor returns the largest integral value that is less than or equal to the specified number. Floor rounds down a value to the nearest whole number.
{{floor field}}
Template | Context | Output |
---|---|---|
{{floor 22.44}} |
{ |
22 |
{{floor 45.25}} |
45 |
|
{{floor 3.14}} |
3 |
getValue
This helper returns the value from the specified field.
{{getValue field "defaultValue"}}
Template | Context | Output |
---|---|---|
{{getValue "legends.unicorns" "defaultValue"}} |
{ |
11 |
{{getValue "legends.ponies" "defaultValue"}} |
22 |
|
{{getValue "legends.total" "defaultValue"}} |
null |
|
{{getValue "name" defaultValue}} |
{ |
Harry S Truman |
Note: The getValue helper method was introduced to retrieve the value from the complete path in the helper method's first argument. The getValue helper fails if used inside the #each block helper because getValue can't derive the complete path for the context of each data iteration.
join
The join helper joins variable output using the specified delimiter and can handle any number of arguments.
{{join delimiterField field1 field2}}
Delimiters:
(parentheses) {braces} [brackets] or /*
Notes:
- If a delimiter array is specified, the specified delimiter is introduced between each array value in the result set
- If a string is specified, the specified subsequent variables are read and the specified delimiter is introduced between them in the result set
Template | Context | Output |
---|---|---|
{{join "**" "unicorns" "ponies"}} |
{ |
unicorns**ponies |
{{join " + " "unicorns" "ponies" "horses"}} |
unicorns + ponies + horses |
|
{{join "-" "unicorns" "ponies" "horses"}} |
unicorns-horses |
|
{{join "-" "legends" "[unicorns, ponies, horses]"}} |
legends-[unicorns, ponies, horses] |
jsonEncode
Encodes the specified JSON object.
{{jsonEncode field}}
Template | Context | Output |
---|---|---|
{{jsonEncode total}} |
{ |
99.99 |
jsonSerialize
The jsonSerialize function converts an object value into a JSON serialized string. Three curly braces are used in this expression.
{{{jsonSerialize field}}}
Template |
{{{jsonSerialize elementals}}} |
---|---|
Context |
{ |
Output |
{"gnomes":"677","salamanders":"422","sprites":"56","faeries":"277"} |
hmac
Keyed-hashing for message authentication (HMAC) is a message authentication code generated via cryptographic hash function (such as MD5, SHA-256 and many more). This crypto key wraps the data until it is authenticated using a shared key. For a complete list of integrator.io support, see Supported encoding algorithms.
{{hmac algorithm key encoding field}}
In this example, the key would be your secret key, or private access key.
Note: Be cautious about exposing the secret key, potentially compromising your system credentials.
Connection details:
- HTTPS should be used, where standard HTTP should be avoided wherever possible
- All PARAMETER values must be URI encoded
- Authorization HEADER {{hmac}} helper must use the "full URL" keyword as the input as the system will calculate the signature based on the complete URL that it receives, including PARAMETER values and the Base URI https
See Using hmacOptions for additional functionality.
length
Counts the length of a given string for use in other functions.
This example counts the length of the state field. If the length is exactly two characters, integrator.io capitalizes the output. If the length is not exactly two characters, the output is "Bad state value".
Template |
{{#compare state.length "===" 2}}{{uppercase state}}{{else}}Bad state value{{/compare}} |
---|---|
Context |
{ { |
Output |
Bad state value IL |
This example uses length with the compare handlebar to verify a phone number field has exactly 10 digits. If not, the output is ten zeros (0000000000).
Template |
{{#compare phone.length "===" 10}}{{else}}0000000000{{/compare}} |
---|---|
Context |
{ |
Output |
0000000000 |
lowercase
Converts all letters in a string to lowercase.
{{lowercase field}}
Template |
{{lowercase 'HERE WE GO!'}} |
---|---|
Context |
{ |
Output |
here we go! |
multiply
Returns the multiplication of the two specified values. Variables may be referenced in the Context, or ““hard-coded” values”.
{{multiply field}}
Template | Context | Output |
---|---|---|
{{multiply unicorns "5"}} |
{ |
55 |
{{multiply "5" "2"}} |
10 |
|
{{multiply horses ponies}} |
726 |
random
Generates a random number with an input field for the length. The default value needs to have either “CRYPTO” or “UUID” added to the template to generate the number.
{{random "CRYPTO" length}}
or
{{random “UUID” length}}
- "CRYPTO/UUID": the method for random number generation
- "length": integer value for the number of places in the output
Template | Context | Output |
---|---|---|
{{random “UUID” 5}} |
{ |
5e3ca |
{{random “CRYPTO” 8}} |
4ccb3420 |
- Alphanumeric 9 character string:
{random “UUID” 9}
- Numeric 9 character string:
{random “CRYPTO” 9}
regexMatch
Matches the input data based on the regular expression and returns the data based on index and options variables.
{{regexMatch field regex index options}}
- field: the field name containing the variable or values to be replaced. You can reference a field or variable by typing its name without double quotes (or curly braces or parens).
- regex: the new value which will replace the existing value.
- index: here, index refers to a the location of the numerical range to be examined when searching for matches, which is useful for known values, e.g. [1-4][0-9][5-6].
- options: Regex options allow you to modify the search behavior of the expression. For example, regular expressions stop at the first match in the text content by default. A "g" entered in the options position sets the expression to global (meaning that the expression will attempt to match all instances matched throughout the entirety of the text content). For more information on regex options, see regex options.
Template | Context | Output |
---|---|---|
{{regexMatch secretCode "7" "[0-9]"}} |
{ |
7 |
{{regexMatch secretCode "007" "[0-9]"}} |
007 |
|
{{regexMatch secretCode "[0-2][0-2][5-7]"}} |
007 |
|
{{regexMatch secretCode "[0-9][0-9][0-9]" 1 "g"}} |
{ |
345 |
regexReplace
The regexReplace helper returns a modified string where the pattern has been replaced.
{{regexMatch field regex index options}}
- field: the field name containing the variable or values to be replaced. You can reference a field or variable by typing its name without double quotes (or curly braces or parens).
- regex: the new value which will replace the existing value.
- index: the position of the result in the dataset, where 0=first position and 2=third position.
- options: Regex options allow you to modify the search behavior of the expression. For example, regular expressions stop at the first match in the text content by default. A "g" entered in the options position sets the expression to global (meaning that the expression will attempt to match all matching instances throughout the entirety of the text content). For more information on regex options, see regex options.
In this example, the output has the word “Sequence” replacing the number 6 in the Context.
Template |
{{regexReplace secretCode "Sequence" "[6]"}} |
---|---|
Context |
{ |
Output |
12345Sequence7890 |
Alternately, you could change the price of an incorrect value by entering the number to change and assigning the value of the overwrite. Here, we have modified $249.99 to $549.99 and $9.99 to $19.99 respectively.
Template | Context | Output |
---|---|---|
{{regexReplace total "5" "[2]"}} |
{ |
$549.99 |
{{regexReplace total "19" "[9]"}} |
{ |
$19.99 |
regexSearch
The regexSearch helper uses an expression to search for a match, and returns the position of the result in the dataset, where 0=first position and 2=third position.
{{{regexSearch field regex options}}}
- field: the field name containing the variable or values to be replaced.
- regex: the new value which will replace the existing value.
- options: Regex options allow you to modify the search behavior of the expression. For example, regular expressions stop at the first match in the text content by default. A "g" entered in the options position sets the expression to global (meaning that the expression will attempt to match all matching instances throughout the entirety of the text content).
Template |
{{regexSearch total 5}} |
---|---|
Context |
{ |
Output |
7(where 5 is the eighth value (INDEX location=7) in the “total” JSON field value) |
replace
Replaces all the occurrences of the specified letter in a string with another letter.
{{replace field string string}}
Template | Context | Output |
---|---|---|
{{replace cases "&" "and"}} |
{ |
these and those and some other cases |
{{replace description "Shoes" "Boots"}} |
{ |
Boots |
round
Rounds a number up or down the specified value to the nearest whole value.
{{round field}}
Template |
{{round vat}} |
---|---|
Context |
{ |
Output |
30 |
sort
This helper sorts the specified values in ascending or descending order based on the value specified in the ”reverse” parameter. By default, this helper sorts the array variables in an ascending manner. If the input array contains numerical variables for sorting, set the number parameter = "true". You can also combine reverse and number option parameters in the handlebars expression.
{{sort field number="true" reverse="true"}}
Template | Context | Output |
---|---|---|
{{sort items number="true"}} |
{ |
1,2,3,4,5 |
{{sort items reverse="true"}} |
5,4,3,2,1 |
|
{{sort items}} |
{ |
candy,hat,toy |
split
Splits a series of words separated by delimiters in the context based on an index value, where 0=first position and 2=third position.
{{split field delimiter index}}
Template | Context | Output |
---|---|---|
{{split fullName "-" 0}} |
{ |
Hillary |
{{split fullName "-" 1}} |
Ann |
|
{{split fullName "-" 2}} |
Swank |
|
{{split fullName "-" 0}} |
Hillary |
subtract
Returns a value that is a subtraction of two specified values. Absolute values do not require
context JSON variables.
Note: This helper does not require quotation marks for JSON variables.
{{subtract field field}}
Template | Context | Output |
---|---|---|
{{subtract "6" "3"}} |
{ |
3 |
{{subtract "6" ponies}} |
{ |
-16 |
{{subtract horses "6"}} |
27 |
|
{{subtract ponies unicorns}} |
11 |
substring
Returns a substring of the specified string. This is useful for shortening the names of longer field names.
{{substring stringField startIndex endIndex}}
- stringField is the actual string
- startIndex is index of the actual at which the substring starts, where 0=first position and 2=third position
- endIndex is the index of the actual string where the substring ends, where 0=first position and 2=third position
- endIndex acts like JavaScript and is non-inclusive
Template | Context | Output |
---|---|---|
{{substring "itemizationCode" "0" "4"}} |
{ |
item |
{{substring "inventory" "0" "3"}} |
inv |
sum
Computes the sum of all numbers present in the specified array. The example below only shows integers, but it also works with floats and decimals.
Note: this is different from the add helper function and performs additional calculations.
{{sum field1 field2 field3}}
Template | Context | Output |
---|---|---|
{{sum items}} |
{ |
31 |
{{sum items}} |
{ |
290 |
{{sum (multiply 2 55)}} |
{ |
110 |
timeStamp
Returns the current system date in ISO format, or as specified in the date field in the Context.
{{timeStamp timeZoneField}}
The first example below shows the local time in San Francisco, which is 10:20:58 (HH:MM:SS) but is displayed in Zulu time [Z]. Since San Francisco is -8UTC, the time displayed in the output is 18:20, 58 seconds, and 176 milliseconds Zulu time.
In the second example, current time is also displayed in Zulu time and the time offset (-05:00) is shown as Detroit is five hours behind UTC, or -5 UTC and Hong Kong is eight hours ahead (+8:00).
Template | Context | Output |
---|---|---|
{{timeStamp "America/Detroit"}} |
{ |
2019-11-25T17:30:07-05:00 |
{{timeStamp "Asia/Hong_Kong"}} |
2019-11-26T06:30:07+08:00 |
toExponential
Returns a string representing the specified number in an exponential format. Variables may be referenced in the Context or ““hard-coded” values”.
{{toExponential field fractionDigits}}
- field: is the number or object value to be modified;
- fractionDigits: an optional parameter that will display the provided number of digits after the decimal place.
Template | Context | Output |
---|---|---|
{{toExponential orderId 2}} |
{ |
1.23e+4 |
{{toExponential "12345" 2}} |
{ |
1.23e+4 |
{{toExponential "3.14159265359" 6}} |
3.141593e+0 |
toFixed
This will set a fixed numerical value to the output string, and format the number to a fixed number of decimal places.
{{toFixed field digits}}
- field: the number to be modified
- digits: number of decimal places to be displayed
{{toFixed 123.456789 0}} = 123
{{toFixed 123.456789 1}} = 123.5
{{toFixed 123.456789 2}} = 123.46
{{toFixed 123.456789 3}} = 123.457
{{toFixed 123.456789 4}} = 123.4568
{{toFixed 123.456789 5}} = 123.45679
toPrecision
This outputs scientific notation if there are more integer digits (before decimals) than the specified precision.
{{toPrecision field precision}}
- field: the number to be modified
- precision: number of decimal places to be displayed
{{toPrecision 123.00 0}} = 1e+2
{{toPrecision 123.00 1}} = 1e+2
{{toPrecision 123.00 2}} = 1.2e+2
{{toPrecision 123.00 3}} = 123
{{toPrecision 123456.00 5}} = 1.2346e+5
{{toPrecision 1234567.00 6}} = 123456
trim
This helper will remove (trim) any white space in a Trims whitespace characters present at the beginning and at the end of the string.
{{trim field}}
Use the trim field if you have white space that persists in your file across all values. Here, the whitespace is before the “artist” value as seen in the output like this:

The problem is also evident in the context below, and the example shown in the Template will resolve the white space issue in the output.
Template | Context | Output |
---|---|---|
{{trim library.artist}} |
{ |
Lalo Schifrin |
uppercase
Converts all lowercase characters in the JSON field value or string to uppercase.
{{uppercase field}}
Template | Context | Output |
---|---|---|
{{uppercase "library"}} |
{ |
LIBRARY |
The {{uppercase family.type}} is a member |
{ |
The DOG is a member |
Block Helpers
Block helpers have a hash symbol at the beginning.
#and
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 Contact.offAddress}}true{{else}}false{{/and}} |
{ |
1. true |
{{#and legends.unicorns |
{ |
11-33 |
{{#and firstName lastName}} |
{ |
Hillary Ann |
#compare
The #compare block helper compares two variables using a logical operator.
{{#compare field operator field}} expr {{else}} expr {{/compare}}
The second argument is the arithmetic operator to be used for comparing the two arguments. Optionally, you can also specify the {{else}} expression to render the value when #compare returns FALSE.
In the following example, reversing the operator will change the output to “false”.
Template |
{{#compare sample1 ">" sample2}} true {{else}} false {{/compare}} |
---|---|
Context |
{ |
Output |
true |
Logical Operators for #compare
Operator | Description |
---|---|
< | Less than (a < b) |
> | Greater than (a > b) |
<= | Less than or equal to (a <= b) |
>= | Greater than or equal to (a >= b) |
== | Equal to (a == b) |
=== | Strict equal to (a === b) |
!= | Not equal to (a != b) |
!== | Strict not equal to (a !== b) |
Note: You can reference literal strings in compare statements by surrounding the literal string in double quotation marks. For example: {{#compare record.Domain == "eu.integrator.io"}}
Compare with else
This example shows the #compare block helper with a nested compare expression. The sample compares the quantity order with current inventory levels. It then compares the current inventory levels with items on order. If the order can be successfully filled, the expressions return “Match”. If not, the output returns “Inventory levels too low”.
Template |
{{#compare ordered "<=" stockLevel}}Match{{else compare stockLevel "<" |
---|---|
Context |
{ |
Output |
Match |
#contains
The #contains block helper parses the name:value specified in the block to check for the presence of a given value. If the value specified is not present, then it prints the {{else}} expression.
{{#contains collection field}} expr {{else}} expr {{/contains}}
In the first example, the order.item value is “12345”. The specified value in the #contains block is “5”. Since 5 is a number present in the value, the first expression statement will be displayed. The second example is looking for a “6”. Since 6 is not present, the else statement it output.
Template | Context | Output |
---|---|---|
{{#contains order.item "5"}} |
{ |
Sales ID Found! |
{{#contains order.item "6"}} |
{ |
Sales ID Missing! |
{{#contains order.sales "2"}} |
{ |
Sales ID Found! |
The example below shows an if/then argument against the product and whether or not a product warranty was purchased via an if_else argument against the context fields specified.
Template |
{{#contains ERP_Item "kit"}}+1{{else}}None found{{/contains}} |
---|---|
Context |
{ |
Output |
+1 |
#each
This helper allows you to iterate over a list. Inside the #each block, you can reference the element to be iterated over.
{{#each field}}{{this}}{{/each}}
This example shows a simple record with names. The {{each}} expression will reference the context while the {{this}} expression will iterate over the array of items in the [people] array.
For the example below, in integrator.io, the [people] array must be referenced as absolute path in the Resource path field. If the context was an object (name:value pair), then the path would not need to be set.

Also in this example, the semicolon and space between the expressions will allow spacing and punctuation between the variables on output.
Template |
{{#each people}}{{this}}; {{/each}} |
---|---|
Context |
{ |
Output |
Bertram Gilfoyle; Erlich Bachman; Jin Yang; |
This example shows the system iterating over the array in the "field.names" variables.
Template |
{{#each fields.names}}{{#each this}} Employee {{@key}}: {{this}} |
---|---|
Context |
{ |
Output |
Employee name1: Stacy |
When looping through items in {{#each}}, you can also reference the current loop index.
Template |
System privilege levels: {{@index}} |
---|---|
Context |
{ |
Output |
System privilege levels: |
Additionally for iterating over objects, {{@key}} will reference the current key name. @key will
provide the current index location in an array or the key names in the Context.
Template |
{{#each fields.rights}} |
---|---|
Context |
{ |
Output |
0:system; 1:admin; 2:editor; 3:contributor; 4:viewer; 5:vendor; |
The first and last steps of iteration are noted via the @first and @last variables when iterating over an array. When iterating over an object only the @first is available. Nested each blocks may access the iteration variables via depth based paths. To access the parent index, for example, {{@../index}} can be used.
The each helper also supports block parameters, allowing for named references anywhere in
the block.
Template |
{{#each fields.rights}} |
---|---|
Context |
{ |
Output |
0:system; 1:admin; 2:editor; 3:contributor; 4:viewer; 5:vendor; |
To create a list or convert data based on index location in a record, you can declare an |item| using vertical bars (pipe character), then entering the characters by their respective index locations (where 0=first character).
Template |
{{#each inventoryItems as |item|}} |
---|---|
Context |
{ |
Output |
1: a |
#if_else
The #if _else helper allows an if/then argument.
{{#if field}} expr {{else}} expr {{/if}}
If the argument in the {{#if field}} is true, then it prints the value from the context. If the argument is false (either undefined, null, " ", 0, or [ ] ), then the block prints the else condition. In the first example below, the contact.phone number is present in the context file (true), so according the argument the phone value prints to output. In the second example, the phone name:value pair is absent (false), so the block prints the else statement value (1-800-555-1212).
If Else logical operators
The following logical operators may be used for building an argument or placing arguments inside expressions.
if |
If a specified condition is true, this specifies a block of code to be executed If the condition is false, another block of code can be executed. {{#if data.name}}{{data.name}}{{/if}} |
---|---|
if_else |
This statement is a part of JavaScript's "Conditional" Statements, which are used to perform different actions based on different conditions, and will execute a block of code if a specified condition is true. {{#if Name}}{{Name}}{{else}}{{/if}} |
else | Specifies a block of code to be executed if the same condition is false. |
else_if | Specifies a new condition to test if the first condition is false. |
compare |
Compares two values using logical operators. {{#compare field operator field}} expr {{else}} expr {{/compare}} |
each |
{{#each data.identity-profiles}} {{vid}} {{/each}} |
if_compare |
{{#if data.name}}{{#compare data.name "!=" |
#ifEven
This argument checks to see if a given value is an even number.
{{#ifEven field}} expr {{else}} expr {{/ifEven}}
If the argument results in an even number (true), the value prints to output. If the argument results in an odd number (false), the {{else}} expression displays. A blank expr field prints the value unless text is specified, as shown below.
Template | Context | Output |
---|---|---|
{{#ifEven orders.item1}} |
{ |
2 |
{{#ifEven orders.item2}} |
Odd number value |
|
{{#ifEven orders.item3}} |
The even number value is 8 |
#neither
This helper is used for building true/false arguments.
{{#neither field field}} expr {{else}} expr {{/neither}}
- If both parameters are equal to false, the first expression displays.
- If one or both are equal to true, the {{else}} expression statement displays.
In this example, both the values in the Context are blank /null (which makes the argument true), so the first expression is printed to output.
Template |
{{#neither item1 item2}} |
---|---|
Context |
{ |
Output |
Values are absent for the specified parameters. |
In this example, only one of the Context variables is blank, so the argument will pass the {{else}} statement to the output.
Template |
{{#neither item1 item2}} |
---|---|
Context |
{ |
Output |
Only one of the parameters has a value. |
#or
This helper creates an all-or-nothing argument. It prints the first expression if the argument is true, and the {{else}} expression if the argument is false.
{{#or field field}} expr {{else}} expr {{/or}}
Template | Context | Output |
---|---|---|
{{#or item1 item2}} |
{ |
One or both fields have a data value. |
{ |
Neither field has a data value. |
#unless
The #unless helper is the inverse argument of the #if block helper. The #unless block renders if the #unless expression returns a false value.
{{#unless field}} expr {{else}} expr {{/unless}}
Template | Context | Output |
---|---|---|
{{#unless contact.phone}} |
{ |
Contact phone number is: |
{ |
Phone number missing |
#with
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 |
{ |
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 |
{ |
Output |
Output The author Charles Dickens |
Nesting Block Helpers
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}} |
---|---|
Context |
{ |
Output |
310-555-1234 |
Block Helpers may also be nested as shown below.
Template |
{{#compare customer1 "==" "2"}} |
---|---|
Context |
{ |
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}} |
@Data Variables
@root
You can use the @root data variable to access the root element properties while you iterate in the context of any nested or child elements. The following sample JSON and Template scenarios explain more about @root.
Template | Context | Output |
---|---|---|
{{@root.title}} |
{ |
My New Post |
{{#each array}}{{@root.title}} |
{ |
My New Post |
{{@root.child.childTitle}} |
{ |
Child Title |
@key
This data variable provides the current index location in an array or the key names in the context.
Template | Context | Output |
---|---|---|
{{#each array}} |
{ |
0 1 2 3 |
{{#each @root.child}} |
{ |
Child Title |
{{#each @root}} |
{ |
title body array |
@index
This data variable gives you the current index in an array iteration or in a JSON iteration in the context of #each.
Template | Context | Output |
---|---|---|
{{#each @root.child}} |
{ |
0 1 |
{{#each @root.people}} |
{ |
0 1 2 |
@first
This data variable returns true for the first element of an array or an object.
Template | Context | Output |
---|---|---|
{{#each @root.child}} |
{ |
childTitle |
{{#each array}} |
{ |
0 |
@last
This data variable returns true for the last element of an array or an object.
Template | Context | Output |
---|---|---|
{{#each @root.child}} |
{ |
childBody |
{{#each array}} |
{ |
3 |
Comments
15 comments
Thank you for the reference! Where can I find a list of options for the "options" parameter for regexMatch?
Hi Tony, I've updated the article to link to this resource for regex options: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions. I hope that helps. Thanks for the feedback.
Is there an example for the #switch syntax? It's the only block logical operator that doesn't have any hint as to the syntax.
Hi Jeff Dollard,
Thanks for providing this feedback! We're looking into this for you.
The substring description for the end index doesn't match the behavior. The end index acts like javascript and it's non-inclusive. That should be noted above. This was baffling me for a bit. How did this {{substring "itemizationCode" 0 4}} return "item" ??
Hi David Gollom,
Thanks for letting us know - I updated the article with this note. Is there anything else we should add based on your findings? Thank you so much for your help!
Hi Jeff Dollard,
We haven't found any information on the switch handlebars. Have you had any luck?
Hi Courtney - no luck with the switch syntax, I sort of gave up on guessing at it ¯\_(ツ)_/¯
I found another way to structure my logic, so it didn't keep me from moving forward.
Awesome, glad to hear it, Jeff Dollard! Any cool tips you can share that we could add to the docs?
Shouldn't the output be "123 Anywhere789 Somewhere"? Both have values.
Hi APC DSR,
This image describes why the expression evaluates to false:
We've revised the example for clarity.
Thank you so much for letting us know how we could improve the article, APC DSR! Please let us know if there are other things we can add! We've also added more examples to the #and section. Hope they're helpful!
Jeff Dollard
I want to let you know that the "Switch" syntax is not supported. We are updating this KB. Thanks for bringing it to our attention!
Do sum and add helpers only work with integers or can they be used with decimals/float values?
Hi Jeff Dollard,
That's a great question and we'll update our article accordingly. I just tested this and decimals and floats seem to work fine for both add and sum. Let us know if you run into any issues!
Please sign in to leave a comment.