Handlebars
Handlebars is a JavaScript library used for creating dynamic templates.
It allows you to define templates with placeholders, and these placeholders are replaced with data when the template is triggered with the information sent in the payload.
Handlebars within Sortment support features like conditional operations, loops, date time formatting, partial searches, and custom helpers, making it a very cool tool to use when creating your templates.
Handlebars in Sortment's Templates
To understand how handlebars work, we first need to establish a sample payload, based off which the Handlebars function and applicability can be demonstrated.
{
"members": [
{
"first_name": "John",
"last_name": "Doe",
"city": ""
}
],
"investments": [
{
"amount": 10,
"company": "L&T"
},
{
"amount": 20
}
],
"companies": {
"L&T": "India",
"Apple": "USA"
},
"user_type": "pro",
"period": {
"start": "2023-10-01",
"end": "2023-10-03"
},
"classification": ["active", "pro"]
}
Sortment has default as well as custom handlebars that you can use in your templates. Let’s have a look at what these are and how to use them using the above payload and data as example responses.
Last updated