Variable helpers

All the helpers you can use in your variables can be found in this article

Christiaan Proper avatar
Written by Christiaan Proper
Updated over a week ago

#upper

{{#upper item.name}}

Will turn all letters within this expression to upper case.

#round

{{#round item.discount_percentage}}

Returns the value of a number rounded to the nearest integer.

#truncate

{{#truncate item.description 80 …}}

Shortens field to the number of characters you enter, follows them by the characters after the last no-break space.

#strip_tags

{{#strip_tags item.description}}

Remove all HTML tags from field, for example:

item.description = <h2>I'm a description!</h2>
{{#strip_tags item.description}} = I'm a description!

#stripAndTruncate

{{#stripAndTruncate item.description 50 ...}}

Combination of #truncate and #strip_tags. Shortens field and strips it from HTML tags, for example:

item.description = <h2>I'm a very <span>long description</span> and this isn't pretty in your notification. So you better shorten me and strip me from my HTML tags.</h2>
{{#stripAndTruncate item.description 50 ...}} = I'm a very long description and this isn't pretty...

#explode

{{#explode item.special_price . 1}}

Split fields on character, example:
item.special_price = 23.95
{{#explode item.special_price . 1}} = 23
{{#explode item.special_price . 2}} = 95

#price_format

{{#price_format item.price , . ,-}}

[Character to split on, decimal separator, thousand separator, “,00” replacer]

Format numeric fields with the right thousand and decimal separator.
With the example from above, the output will be:
2897.98 --> 2.897,98 and 2897 --> 2.897,-

#explodeAndFormat

{{#explodeAndFormat price , 1 , .}}
{{#explodeAndFormat price , 2 , .}}

[Character to split on, part to use, decimal separator, thousand separator]

Splits fields on a character and formats them.

#replace

{{#replace item.name find replace}}

Finds characters or strings in fields and replaces them with other values.

#math

{{#math item.price x 2}}

Output values calculated based on a field value. You can use + (plus), - (minus), x (multiply) and / (divide). It returns the value of a number rounded to the nearest integer.

#mathNoRound

{{#mathNoRound item.price x 2}}

Output values calculated based on a field value. You can use + (plus), - (minus), x (multiply) and / (divide). This helper doesn’t round to the nearest integer.

#isType

{{#isType item.bulletpoints array}}
     {{item.bulletpoints.bulletpoint}}
{{else}}
     {{item.bulletpoints}}
{{/isType}}

Checks the variable type, so you can change the output based on its type.

Possible variable types:

  • string

  • object

  • array

  • number    // Accepts decimals and integers

  • decimal

  • integer

#lowestPrice

{{#lowestPrice item.price item.sale_price , . ,- € left}}

The lowestPrice helper is used to determining the lowest price between two item price fields. It also provides options for formatting the price output. The lowestPrice helper takes the following parameters:

  • price 1, like item.price: The first item price field.

  • price 2, like item.sale_price: The second item price field.

The lowestPrice helper allows for optional formatting settings. These settings are used to format the price output. The optional formatting settings are specified after the item price fields and are separated by commas.

The following formatting settings are available:

  • , . ,-: Specifies the formatting for the price. It works similarly to the #price_format helper.

  • € left: Specifies the currency settings. The first part represents the currency symbol, and the second part indicates whether the currency symbol should be positioned to the left or right of the price.

The entire formatting settings part, including , . ,- and € left, is optional. In particular, the € left part can be omitted.

Note: If the lowest price is 0, the helper will not return any output.

#highestPrice

{{#highestPrice item.price item.sale_price , . ,- € left}}

The highestPrice helper is used to determine the highest price between two item price fields. It also provides options for formatting the price output. It behaves the same as lowestPrice does, so read the documentation above to know more about this helper.

#if

{{#if item.special_price}}
     This item is on sale from €{{item.price}} for €{{item.special_price}}!
{{else}}
     This item costs €{{item.price}}.
{{/if}}

Only show content field when field is present for content item.

#ifEqual

{{#ifEqual item.sale yes}}
     This item is on sale!
{{else}}
     We're always the cheapest.
{{/ifEqual}}

Only show content field when field is equal to string (else statement is required, but can be blank).

#ifGreater

{{#ifGreater item.tickets 100}}
     Over 100 tickets available.
{{else}}
     Hurry! Only {{item.tickets}} tickets left!
{{/ifGreater}}

Only show content field when field is greater than integer (else statement is required, but can be blank).

#ifLess

{{#ifLess item.tickets 100}}
     Only {{item.tickets}} tickets left!
{{else}}
     You're an early bird, get 10% discount.
{{/ifLess}}

Only show content field when field is less than integer (else statement is required, but can be blank).

#ifIsset

{{#ifIsset item.special_price}}
     This item is on sale from €{{item.price}} for €{{item.special_price}}!
{{else}}
     This item costs €{{item.price}}.
{{/ifIsset}}

Determines if a variable is set and is not NULL.

#ifContains 

{{#ifContains haystack needle exactMatch}}
// exactMatch can be true or false.
// Example:

{{#ifContains haystack needle false}}
     There is a needle in the haystack!
{{else}}
     No needle in this haystack.
{{/ifContains}}

Haystack can be an array or string.
If haystack is an array exactMatch is true by default.

Example result of exactMatch:
item.fruit = ['apple', 'banana', 'pear'];

{{#ifContains item.fruit 'app'}} // Result: false
{{#ifContains item.fruit 'app' false}} // Result: true
{{#ifContains item.fruit 'apple'}} // Result: true

Two fields in one #if helper

{{#ifLess item.special_price item.original_price}}
     This item has a discount!
{{else}}
     Normal price
{{/ifLess}}

Using two item fields in one IF statement (else statement is required, but can be blank)

#predictvalue

{{#predictvalue "Recommended for you|Best seller|You may like this|What other customers are buying"}}

Returns the most potential value per user.

#predictvalue item

{{#predictvalue item "Just stock_count_max5 in stock|Viewed view_count_min5 times today|Last bought persuasion_label_last_conversion_EN|Bought persuasion_label_sold_today_min2 times today"}}

Returns the most potential value per item per user and is. This helper can only be used in products of our product recommendations since Datatrics needs to match the values with a product.

If you don’t want to show labels on all products, you can add a few vertical bars ( | ) at the end, before: "}}.

Options:

  • Just stock_count_max5 in stock

  • Viewed view_count_min5 times today

  • Last bought persuasion_label_last_conversion_EN

  • Bought persuasion_label_sold_today_min2 times today

#each

{{#each items}} itemcount='3'

{{VARIABLE}}
{{name}}
{{price}}
{{description}}
{{url}}
{{image}}

{{/each}}

Display multiple items filtered/selected in touchpoint. Note that you don’t need to declare “item.” in every expression, because you are already looping through items.

#eachSlice

{{#eachSlice items 0,1}} itemcount='6'
{{name}}
{{/eachSlice}}
{{#eachSlice items 1,2}}
{{name}}
{{/eachSlice}}
{{#eachSlice items 3,2}}
{{name}}
{{/eachSlice}}
{{#eachSlice items 5,1}}
{{name}}
{{/eachSlice}}

Display items and split them up in sections. It works like this (note: the items start at 0):
{{#eachSlice items starting_item_number,amount_of_items_to_output}}
{{name}}
{{/eachSlice}}

You can use this method to style certain items differently than others in recommendation blocks.

#fieldfunction

{{#fieldfunction discountfunction itemname=name price=price discount=b2bdiscountperc}}

You can also create your own helpers with JavaScript. More explanation of this can be found over here.

Do you have a good addition to our helpers or are you not sure how you need to use one? Send us a chat!

Did this answer your question?