Handlebars Placeholders

Handlebars Placeholders

Carma supports handlebars as method for using placeholders in email, custom tracking and dynamic HTTP requests to name a few examples.

The structure of how to create a placeholder based upon handlebar code is as below Carma also offers a way to create snippets (or macros) for your created and often used handlebars.
To dig into handling Snippets, please read here!

 

Recipient data related

“contact” specifies the recipient

“attributename” specifies the specific attribute connected to your contact

All handlebars must start and end with “{{“ “}}“

So an example of making a placeholder for the recipient data “FirstName” would look like:

{{contact.firstName}} and adding this into the email content would replace the placeholder with the actual data in the field “FirstName” of the recipient/contact.

 

Functions with recipient data (contact+attributename)

You can modify capitalization with handlebars e.g.

{{capitalize contact.city}} Stockholm

{{lower contact.city}} stockholm

{{upper contact.city}} STOCKHOLM

Modify date format and/or Url-encode

{{date contact.dateOfBirth “MM/dd yyyy”}}

{{urlEncode contact.firstName}}

<a href=”{{noEncode contact.linkTarget}}”>

<a href=”{{contact.linkTarget}}”>

 

Print (set a different value from what’s in list, or if value is “empty”)

{{#print contact.firstName}}<span class=”noname”>no name specfied</span>{{/print}}

{{#upper}}{{print contact.firstName “no value specified”}}{{/upper}}

 

Compare and print (if value more than 100 prints Goldmember etc)

{{#switch contact.bonusLevel}}{{#compare ">" 100}}Goldmember{{/compare}}{{#compare "<" 100}}Silvermember{{/compare}}{{#default}}New{{/default}}{{/switch}}

PLEASE NOTE: All handlebars working in email content are also working in links and in tracking, however remember that when in links the result value will be URL-encoded.

Compare operators

Greater than

“>”

How to use:

{{#compare ">" 100}}

Result: Matches if value is greater than 100.

Lesser than

“<“

How to use:

{{#compare "<" 100}}

Result: Matches if value is lesser than 100.

Equals

“==”

How to use:

{{#compare "==" 100}}

Result: Matches if value is equal to 100.

PLEASE NOTE: This can both compare strings and numbers. When comparing strings case is ignored.

Modular

“%”

How to use:

{{#compare "%" 4 0}}

Result: Matches if value is dividable by 4 with rest 0.

All compare operators can be negatory with prefix “!”

How to use:

{{#compare "!=" 100}}

Result: Matches if value is not 100.

 

Aritmetic operators

{{add contact.value1 contact.value2}} – adding values in attributes “value1” and “value2”

{{subtract contact.value1 contact.value2}} – subtracts values in attributes “value1” and “value2”

{{multiply contact.value1 contact.value2}} – multiplying values in attributes “value1” and “value2”

{{divide contact.value1 contact.value2}} – dividing values in attributes “value1” and “value2”

{{dateAdd contact.birthdate 2 “DAYS”}} – adding 2 days

{{dateAdd contact.birthdate 2 “WEEKS”}} – adding 2 weeks

{{dateAdd contact.birthdate 2 “MONTHS”}} – adding 2 months

{{dateAdd contact.birthdate 2 “YEARS”}} – adding 2 years

{{dateAdd contact.birthdate 2 “DAYS” “MM/dd/YYYY”}} – add 2 days in mm/dd/yyyy fromat

{{random 1 1000}} – set a random number between 1 – 1000

 

System related entities

{{contactdb.id}} – recipient list ID

{{contactdb.name}} – recipient list name

{{contact.id}} – a recipients OriginalID

{{message.id}}  the system ID of the message

{{message.guid}} – 

{{message.sendtime}} – returns the sent time stamp in full ISO8601-format, i.e  yyyy-MM-dd’T’HH:mm:ss.SSS, i.e 2014-06-25T15:30:24.123. For other formats, use the date functionality specified further below.

{{message.abslice}} (‘A’, ‘B’, ‘C’ eller ‘D’) If the message is sent as a part of an AB(CD) test. PLEASE NOTE: If the actual message happens to be part of the winning version, the slice from the winning version will be returned.

{{campaign.id}}  – the DeliveryID of the Email

{{campaign.name}}  – the name of the Email

{{campaign.segmentid}}  – master segment rule ID. PLEASE NOTE: If you get -1 (minus one) no master rule exists as with Transactional send outs.

{{campaign.segmentname}}  – master segment rule name

{{project.id}}  – the ID of the Project

{{project.name}}  – the name of the Project

{{link.id}}  – the ID of the link

{{link.name}}  – the name of the link

{{link.categories}}  – a comma separated string containing all categories added to the link

{{link.segmentid}}  – the ID of the segment added to the block which contains the link when content segmentation

{{link.segmentname}}  – the name of the segment added to the block which contains the link

{{link.clicktime}}  – returns the time of the link click in full ISO8601-format, i.e yyyy-MM-dd’T’HH:mm:ss.SSS, i.e 2014-06-25T15:30:24.123. For other formats, use the date functionality specified below.

{{message.sendtime}} and {{link.clicktime}} is returned in full ISO8601-format. For other formats, use the date functionality {{date ‘yyyy-MM-dd HH:mm’ link.clicktime}}

Note the re-order of the arguments in the date functionality. Date format is now prior to the contact date type which is the second argument instead. This is because you call the date function as a block-function

{{#date ‘yyyy-MM-dd’}}{{contact.registrationDate}}T{{contact.registrationTime}}{{/date}}

Note that the date function input (e.g the date about to be formatted) should be a ISO8601- formatted string based upon the format yyyy-MM-dd’T’HH:mm:ss.SSS. Not all fields are mandatory though so it works with i.e

yyyy-MM-dd, yyyy-MM-dd’T’HH, yyyy-MM-dd’T’HH:mm, yyyy-MM-dd’T’HH:mm.ss, or yyyy-MM-dd’T’HH:mm.ss.SSS.

Purchase History data and Handlebars

There are at the moment three handlebars available for your Purchase History column data for message content use:

{{ph.first.column}}

{{ph.last.column}}

———————–

{{#each ph.all}}

{{this.column1}}

{{/each}}

———————–

Apart from adding column 1-26 to these handlebars you can also use the static Purchase History columns:

transactionDate

ItemPrice

ItemCount

TotalPrice

 

Status

i.e {{ph.first.transactionDate}}

Note, its also possible to combine above handlebars with existing handlebars functions for dates

{{date ‘MM/dd/yyyy’ ph.first.transactionDate}}

 

 

Also, a set of new PH-Handlebars that will be released on servers during Autumn 2016 are:

The handlebar for segmentet result on PH will work as follow.

We will merge ALL the Purschase History parts of rules in:

– Customer master rule (not currently implemented in UI)

– Project rule AND

– Auto rule AND

– Delivery rule AND

– Block rule (that is on the current block)

the union of all these become the eye of the needle Purchase History – line may pass through

 

The segmented handlebar syntax:

{{ph.lastInSegment.<column1>}}

{{ph.firstInSegment.<column1>}}

 

{{#each ph.allInSegment}}

{{<column1>}}

{{/each}}

 

If no purchase history rule is found it will work as it does for the {{ph.first.<column1>}}, {{ph.last.<column1>}}

{{#each ph.all}}

{{this.column1}}

{{/each}}

 


Regular expression functionality

Regular expression functionality is available using the syntax:

{{#regex valueToMatchIn regexPattern}}

Custom text and matched values using {{match.1}}, {{match.2}}, etc.

{{/regex}}

valueToMatchIn can be a model-attribute like contact.firstName or a hard-coded string “Hello world”. 

regexPattern uses Java SE 7. Documentation at:

https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

Practical example:

{{#regex ‘Hello World!’ ‘(.+) [World](.)’}}

{{match.1}} Universe{{match.1}}

{{/regex}}

Results in: Hello Universe!

 

Substring functionality is available using the syntax

{{#substring beginIndex endIndex}}

 value
{{/substring}}

or short

{{substring beginIndex endIndex value}}

beginIndex is base 0 and endIndex is non-inclusive.

Practical example:

for context: myValue = “This is my Hello World! string”

{{substring 11 23 myValue}}

Results in:

Hello World!

More examples

Dynamic Content