Global helper functions

You can use any of the global helper functions listed below when developing your templates. These functions can be used with any of our platform connectors.

$parseJSON

Receives a string as input (in stringified JSON format) and returns a JSON object.

Template compatibility: All

Input

Any string

Examples

$parseJson('{"foo": "bar"}')
=> { foo: 'bar' }

$or

Coalesces any number of values. Equivalent to the || (logical or) operator. It returns the first value that is not falsy. If all values are falsy, it returns the last one.

Template compatibility: All

Input

Any number of any arguments

Examples

$or(1, 2)
=> 1

$or(null, 3)
=> 3

$or(null, '')
=> ''

$includes

Returns a boolean indicating if a value is contained within an array. Equivalent of [].includes(payload).

Template compatibility: All

Input

[an array, any value]

Examples

$includes(['foo', 'bar'], 'foo')
=> true

$includes(['foo', 'bar'], 'baz')
=> false

$deepMutate

Deeply mutates an object with the payload. Instead of creating new memory, this directly updates a reference that already exists, thus being more performant and useful for heavy computational cases.

Template compatibility: All

Input

[an object, an object]

Examples

$person := {
  "name": "Bob",
  "age": 25,
  "metrics": {
    "height": 170,
    "weight": 50
  }
};

$deepMutate($person, {
  "name": "Alice",
  "metrics": {
    "weight": 40
  }
});

=> {
  "name": "Alice",
  "age": 25,
  "metrics": {
    "height": 170,
    "weight": 40
  }
}

$forceReturnArray

Forces any return type to be an array. If an array is provided, it won't be changed.

Template compatibility: All

Input

Anything

Examples

$forceReturnArray(42)
=> [42]

$forceReturnArray([42])
=> [42]

$kebabCase

Converts a string into the kebab-case format. Note that words and numbers will be separated based on casing.

Template compatibility: All

Input

A string

Examples

$kebabCase('The quick brown fox jumps over the lazy dog')
=> 'the-quick-brown-fox-jumps-over-the-lazy-dog'

$kebabCase('TheAnswerIs42')
=> 'the-answer-is-42'

$snakeCase

Converts a string into the snake case format. Note that words and numbers will be separated based on casing.

Template compatibility: All

Input

A string

Examples

$snakeCase('My Product Name')
=> 'my_product_name'

$snakeCase('TheAnswerIs42')
=> 'the_answer_is_42'

$flattenArray

Recursively flattens an array. If the payload is not an array, it'll be converted to one.

Template compatibility: All

Input

An array

Examples

$flattenArray([['foo'], ['bar', ['baz']]])
=> ['foo', 'bar', 'baz']

$flattenArray(42)
=> [42]

$objectValues

Returns the values of an object as an array. Returns an empty array if the payload is falsy.

Template compatibility: All

Input

An object

Examples

$objectValues({"foo": "bar", "baz": "qux"})
=> ['bar', 'qux']

$objectValues(null)
=> []

$getHTMLText

Extracts the text from an HTML string, such as a product description.

Note that this will limit the string to 1000 characters.

Template compatibility: All

Input

A string

Examples

$getHTMLText('<p>This is a <bold>text</bold></p>')
=> 'This is a text'

$truncateFacet

Truncates the value of a facet to its limit of 200 characters. The facet value type will be kept, either as a string or an array of strings.

If the value is an array, each entry will be truncated separately.

Template compatibility: All

Input

A string or an array of strings

Examples

$truncateFacet('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam imperdiet ac magna non venenatis. Nunc faucibus maximus accumsan. Donec consequat nulla eu elit sagittis sodales. Aliquam dignissim magna id convallis placerat. Cras vitae scelerisque nibh.')
=> 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam imperdiet ac magna non venenatis. Nunc faucibus maximus accumsan. Donec consequat nulla eu elit sagittis sodales. Aliquam dignissim magna'

$truncateFacet(['foo', 'bar'])
=> ['foo', 'bar']

$dateFormat

Formats a date string into another format.

Input

The first input is your date, and the second input is your format.

Example

$dateFormat('2025-07-15T19:43:37Z', 'DD/MM/YYYY')
=> '15/07/2025'

$dateAdd

Adds some period to a given date.

Input

The first input is your date, the second is the amount to add, and the third is the period you want to use.

Example

$dateAdd('2025-07-15T19:43:37Z', 7, 'day') // period could be 'day', 'month', 'year', 'hour', etc
=> '2025-07-22T19:43:37Z'

$dateSubtract

Subtracts some period from a given date.

Input

The first input is your date, the second is the amount to subtract, and the third is the period you want to use.

Example

$dateSubtract('2025-07-15T19:43:37Z', 7, 'day') // period could be 'day', 'month', 'year', 'hour', etc
=> '2025-07-08T19:43:37Z'

$isDateBefore

Returns true if a given date is before another date.

Input

The first input is your date. The second one is the comparison date.

Example

$isDateBefore('2025-07-15T19:43:37Z', '2025-07-17T19:43:37Z')
=> true

isDateAfter

Returns true if a given date is after another date.

Input

The first input is your date. The second one is the comparison date.

Example

$isDateAfter('2025-07-15T19:43:37Z', '2025-07-14T19:43:37Z')
=> true

isDateBetween

Returns true if a date is between two dates (inclusive)

Input

The first input is your date, the second is the lower date, and the third is the higher date.

Example

$isDateBetween('2025-07-15T19:43:37Z', '2025-07-13T19:43:37Z', '2025-07-17T19:43:37Z')
=> true