String Formatting

ActivatePro offers two string formatting functions:

  1. trim - used to remove whitespace around a string
  2. substring - used to display a substring of an existing string

trim Function

The trim helper function removes white spaces from the start and end of a string. The syntax of this formatting function is:

{{#trim}}{{[attribute]}}{{/trim}}
Property Description
attribute Any user or event attribute or any information extracted through any of the helper functions. e.g. {{user.[traits.email}}

Removing the white space around an email attribute

For the example below, we use john.doe@example.com as the value of the user's email attribute.

{{#trim}}{{user.[traits.email]}}{{/trim}}

Once the function is evaluated, it displays john.doe@example.com in the section where it is used in the message. 

Removing the white space around a product name field

Using the helper function #findProduct, we search for a particular sku and format the result's [properties.name] attribute. For the example below, we use iPhone 8 Plus as the value of the product's name.

{{#trim}}{{[properties.name]}}{{/trim}}

Once the function is evaluated, it displays iPhone 8 Plus in the section where it is used in the message. 

substring Function

To extract a substring from a text field, we can use the substring function. This can be quite useful in breaking down text fields such as address, IBAN, or Business Unit, where different parts of the string might have Independent meaning.eaning.

{{substring '{ 
"propertyName": [Attribute],
"start": [Substring start],
"length": [Substring length]
}' }}
Property Description
propertyName Required. Any user or event attribute or any information extracted through any of the helper functions.
start Required. The index of the character in the original string where the substring starts. e.g. 1 refers to the first character in the string, 3 to the third character.
length Required. The number of characters the substring extracts from the original string. e.g. 10

Example with inserting a user-trait:

{{substring '{
"propertyName": "user.[traits.phoneNumber]", 
"start": 2, 
"length": 10 
  }'}}