Articles in this section

Handlebars helper equivalents for common JavaScript functions

JavaScript is a powerful way to transform data and customize flow steps in integrator.io, and Handlebars helpers let you reference settings and manipulate records in low-code expressions. The two overlap in what they can do, but in some flow settings, Handlebars is the only option. If you already know JavaScript, this article maps common JavaScript string methods to their Handlebars helper equivalents, by example.

Input

All examples use the following input. In the JavaScript snippets, OGLink refers to the record (the same object shown as record in the input).

{
  "record": {
    "Photos": "/core/media/media.nl?id=1941340&c=5836838_SB2&h=h3Vx0oaIE8OYfVMDfw2G_Yg9Hif_U-VI2DhebnE5vauVwAHs"
  }
}

split()

This JavaScript splits the string in record.Photos into an array using the delimiter "?id=", and [1] selects the second element — the part of the string after "?id=".

var usingSplit = OGLink.Photos.split("?id=")[1];
options.record.usingSplit_m = usingSplit;

Handlebars equivalent:

{{split record.Photos "?id=" 1}}

replace()

This JavaScript replaces the substring "/core/media/media.nl?id=" with an empty string, removing it from record.Photos.

var usingReplace = OGLink.Photos.replace("/core/media/media.nl?id=", "");
options.record.usingReplace_m = usingReplace;

Handlebars equivalent:

{{replace record.Photos "/core/media/media.nl?id=" ""}}

match()

This JavaScript matches the substring from id= to the end of the string, using the regular expression id=.*$.

var usingMatch = OGLink.Photos.match("id=.*$");
options.record.usingMatch_m = usingMatch;

Handlebars equivalent:

{{{regexMatch record.Photos "id=.*$"}}}

exec() to capture text after a delimiter

This regular expression uses a positive lookbehind, (?<=id=), to capture the part of the string after id= without including id= itself. In the Handlebars equivalent, the index 0 selects the entire matched substring, and the g (global) and m (multiline) flags allow multiple matches across lines.

var usingExec = /(?<=id=).*$/.exec(OGLink.Photos);
options.record.usingExec_m = usingExec;

Handlebars equivalent:

{{{regexMatch record.Photos "(?<=id=).*$" 0 "gm"}}}

exec() to capture digits after a delimiter

This regular expression uses the same (?<=id=) lookbehind, then \d* to match the sequence of digits that follows id=.

var usingExec2 = /(?<=id=)\d*/.exec(OGLink.Photos);
options.record.usingExec2_m = usingExec2;

Handlebars equivalent:

{{regexMatch record.Photos "(?<=id=)\d*" 0 "gm"}}

Notes and considerations

  • Use triple braces ({{{ }}}) when the extracted value might contain characters that integrator.io would otherwise escape, such as &. Use double braces ({{ }}) when the value is plain text, such as digits.
  • The JavaScript replace() method replaces only the first match of a string argument, whereas the replace Handlebars helper replaces every match. This difference matters when the substring appears more than once.