Articles in this section

Handlebars helper equivalents for common JavaScript functions

JavaScript offers a powerful tool for transforming data and customizing flow steps throughout the Celigo platform, and handlebars helpers allow you to similarly reference settings and manipulate records in low-code statements. In fact, there is much overlap in what you can accomplish with them, but often handlebars are the only option available in a particular setting when building your flow. For those customers who are already JavaScript experts, this article presents a quick-start guide to finding the equivalent handlebars helper, by way of example.

Input

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

split() example

This JavaScript code calls the split() method to break the string in record.Photos into an array of substrings based on the delimiter "?id=". The [1] at the end selects the second element of the resulting array, effectively extracting the portion of the string that comes after "?id=".

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

Handlebars equivalent

{{split record.Photos "?id=" 1}}
23145556821019-split.png

replace() example

This code utilizes the replace() method to substitute the substring "/core/media/media.nl?id=" with an empty string ("") in the record.Photos value. It effectively removes the specified substring from the original string.

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

Handlebars equivalent

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

match() example

Here, the match method is employed with a regular expression id=.*$. This regex matches the substring starting from id= to the end of the string (.*$). The result is an array containing the matched portion of the string.

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

Handlebars equivalent

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

exec() example A

This regex includes a positive lookbehind (?<=id=), capturing group () (and the global [g] and multiline [m] flags in the corresponding handlebars statement). It captures the portion of the string that follows id= without including id= itself. The 0 in $0 refers to the entire matched substring. The global flag allows multiple matches, and the multiline flag enables matching across multiple lines.

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

Handlebars equivalent

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

exec() example B

This is a positive lookbehind assertion. It asserts that what precedes the current position in the string is the literal string "id=". The portion \d* matches any sequence of digits (\d) including zero or more occurrences (*).

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

Handlebars equivalent

The flag g stands for global, allowing the regular expression to match all occurrences in the string. The flag m stands for multiline, allowing the ^ and $ anchors to match the start and end of each line in a multiline string.

{{regexMatch record.Photos "(?<=id=)\d*" 0 "gm"}}
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.