Outline:
- Overview
- What is Handlebars?
- Basic Syntax
- Adding Product Information
- Using Loop
- Previewing your work
Overview
Within your Skio account, you can use variables to populate subscription specific details in the notifications sent to your customers. These variables are using Handlebars. Handlebars is a popular templating engine that allows you to build dynamic templates with ease. This article will guide you through the process of using Handlebars variables in your templates.
What is Handlebars?
Handlebars is a simple templating engine that lets you build semantic templates effectively. It uses a syntax that allows you to insert dynamic content into HTML, which can be particularly useful for web applications and static site generators.
Basic Syntax for Variables
In Handlebars, you use double curly braces ({{ }}
) to insert variables into your templates. Here’s a basic example of how to use a variable:
Hello, {{first_name}}
{{first_name}}
is a variable that will be replaced with the actual value when the template is rendered. For example, if the customer's first name is "Kennan" then the output would be "Hello, Kennan".Adding Product Information to Templates
In some templates, you may want to add in the different product names, variant names, or quantities as variants so when the customer receives the notification, they see which products they are subscribed to. In order to do this, you'll need to use a loop! This allows the notification to look at each product on that subscription, and add in the required details. If you do not have the loop, these variables will not work.
The following variables require the loop to work:
- {{product_variant_name}}
- {{product_name}}
- {{product_variant_quantity}}
Using Loops in Templates
The Handlebars in Skio provides the {{#product}}
variable to iterate the products. To end the loop, you need you use {{/product}}
at the end to close it out.
Here's an example of using this loop:
<ul>
{{#product}}
<li>{{product_name}} - {{product_variant_name}} - Qty: {{product_variant_quantity}}</li>
{{/product}}
</ul>
In this example, {{#product}}
iterates over each item in the items array and renders a <li> (or bullet point) element for each product. On the line, it shows the product name, product and variant name, then the quantity. The output would look like so:
- Apples - Apples 10 Pack - Qty: 2
- Oranges - Oranges 10 Pack - Qty: 1
The {{product_variant_name}}
variable includes the product name (also called the product title) and variant name (aka, variant title), so you may not need to use both {{product_variant_name}}
and {{product_name}}
in your templates to meet your needs.
Previewing your work
When working with the templates in Skio, there is a preview of what the message will look like below the code block. If the variables are replaced with placeholder information, then the variables are set up correct, like so:
{{#products}}
{{/products}}
variables, or typing product instead of products (with the S on the end).If you have any questions or need further assistance, feel free to reach out to our support team or consult the Handlebars documentation.
Related to:
Add comment
Article is closed for comments.