You will learn
Learn how to use dynamic blocks personalize the content of your flow emails.
Within a flow, you’re able to personalize the content of your emails based on the event that triggers the flow. For example, if someone starts a checkout, you can include product images and prices within an abandoned cart email to encourage recipients to return to their cart and finish their purchase.
While Klaviyo comes prepopulated with a handful of built-in dynamic blocks within the emails in the flow library, you can build out and customize these blocks on your own as well.
In this article, we’re going to build out an abandoned cart dynamic block as an example of how you can use event data within a flow email.
Are you using Klaviyo’s new template editor? Learn how to build dynamic blocks in flow emails in the new editor.
Before you begin
Before you can jump in, you’ll want to make sure that you have an ecommerce integration enabled with Klaviyo. If you're building out the abandoned cart example, and if you’re using a custom integration, make sure it's pulling in checkout started data. If you’re using a built-in integration (i.e. BigCommerce, WooCommerce, Magento, Shopify, etc.), the integration will pull in this information automatically.
Creating a dynamic block
Checklist
The steps for creating a dynamic block are as follows:
- Create your flow
- Add a dynamic table
- Capture the event variable
- Establish a data source
- Include the product title
- Add an image
- Show the quantity and total for the product (optional)
- Link to the product page (optional)
- Preview your email
Step 1: Create your flow
First, you must create a flow that is triggered by an event (or metric). In this example, because we are building an abandoned cart block, we need our flow to be triggered by the Started Checkout event. This ensures that we have access to the event data necessary to construct an abandoned cart block.
You can customize any of your flow emails using this same process, but you’ll have to change the metric to have access to other information being pulled into Klaviyo. For example, if you would like to include information in a post-purchase email about the item someone bought, you will need to make sure that the flow is triggered by the Placed Order event.
From there, you can drag and drop an email into the flow, and customize it.
Step 2: Add a dynamic table
- Drag a table block into your email
- Delete the third column and column headers within the block columns as well as the divider, which can be adjusted under theBlock Styles tab
- Go to Rows
- Switch the table from Static to Dynamic
- Tip: if you have already written a message in one of the cells, copy the message prior to changing the table to Dynamic, as doing so will automatically erase the contents of a table
Step 3: Capture the event variable
- Go into Preview tab to pull up the available dynamic variables
- Scroll down to the title for one of the products abandoned in a cart to find the event variable: {{ event.extra.line_items.0.product.title }}
- Note that this contains more information about the product than {{ event.Item }}, which is simply the name of the item
In the image above:
- Blue is the variable array
- Yellow is the array number
- Orange is the specific variable
We will be using each at different points going forward, so it's important to know which is which.
Step 4: Establish a data source for the dynamic table
- Click Data Source
- Replace Items in the Row Collection field with he variable array you want to repeat (e.g., event.extra.line_items)
- Leave item as the Row Alias
Step 5: Include a dynamic product title
Since this email is for an abandoned cart flow, it’s important to show the name of the product left behind.
- Navigate to one of the columns.
- Click on the column where you want the text
- In this case, we want the text on the right, so choose Column 2
- Paste in the full event variable; for instance: {{ event.extra.line_items.0.product.title }}
- Replace the collection for the variable (the text you used for the Row Collection) and the following number with the Row Alias (e.g., item)
- For this example, {{ event.extra.line_items.0.product.title }} now becomes {{ item.product.title }}
- Preview the email to ensure that the title shows up
- If it doesn’t appear, double-check the spelling, capitalization, and formatting of the text here to make sure the variable matches how it appears in Data Source
Step 6: Add an image
Here, it is under src: {{ event.extra.line_items.0.product.images.2.src }}. Note in this tag, we are specifically referencing the third image (0, 1, 2, etc.) in the event variable array that holds images (event.extra.line_items.0.product.images). This is an event variable array within the event variable array event.extra.line_items, which holds the images for this specific item.
- Find the event variable for the image in the preview window
- The variable's location depends on your integration
- Commonly, the variable is listed under: image, img, or src
- Example: {{ event.extra.line_items.0.product.images.2.src }}
- Head to the column where you want to display the image
- In this case, we want the image on the left, so choose Column 1
- Change the column to Image
- Choose Browse and then select Placeholder
- Input the image event variable, replacing the collection and following number with the alias
- For this example, {{ event.extra.line_items.0.product.images.2.src }} becomes {{ item.product.images.2.src }}
- Do not remove the number near the end (e.g., the 2 before src)
- Click Save
- Check the Fill Image Area checkbox and set the pixel size (
- 250 px is good in most cases
- 250 px is good in most cases
- Click Save
- Preview your image to make sure it appears as expected
- If an image doesn’t appear, check the spelling of the variable under Placeholder against the one in the preview window
Step 7 (Optional): Show the quantity and total of a product
Quantity
- Navigate back to the column where you added the product title (e.g., Column 2)
- Type “Quantity:” in the text box
- Navigate to the preview window to find the event variable
- Example: {{ event.extra.line_items.0.quantity }}
- Example: {{ event.extra.line_items.0.quantity }}
- Exit the preview window
- Paste the variable next to “Quantity”
- Replace the collection and number with the alias
- Example: {{ item.quantity }}
Total
- Navigate back to the column where you added the product title (e.g., Column 2)
- Type “Total:” in the text box
- Navigate to the preview window
- Use the line_price event variable to show the total price of a product based on the quantity
- Example: {{ event.extra.line_items.0.line_price }})
- For instance, if you have a lipstick that costs $12, and someone has added two of them, the line price will show as $24
- Paste the variable next to “Quantity”
- Replace the collection and number with the alias
- Example: {{ item.line_price }}
- Optional: Show the currency by either:
- Adding in the currency symbol before the brackets
- Example: ${{ item.line_price }}
- Adding % currency_format inside the brackets before the event variable and another % before the closing brackets
- Example: {% currency_format item.line_price %}
- Adding in the currency symbol before the brackets
Note that the currency format tag cannot be used with the float format filter.
Change how a number Is displayed via the float format filter
By default, numbers will be shown as X.0 (with at least one decimal place). If you’d like to change this format, you can do so with the float format filter.
Adding |floatformat:0 into the brackets will get rid of the decimal point and following number while |floatformat:1 will display with one number after the decimal point, |floatformat:2 will display with two, and so on. Learn more about using filters.
Step 8 (Optional): Link to the product page
- Open the preview window
- Locate the event variable for the product handle
- Navigate to the column with the image (e.g., Column 1)
- Paste the event variable in the field for Link
- Example: {{ event.extra.line_items.0.product.handle }}
- Replace the collection and number with the alias
- Example: {{ item.product.handle }}
- Include the following before the variable you just added
- A link to your store
- OR
-
{{ organization.url }}
- If you use this tag, set your link protocol to <Other> instead of http or https
- If you use this tag, set your link protocol to <Other> instead of http or https
- Click Save
Depending on the properties passed on the event, the structure of this link for the product page may differ. For example, an event property may contain the full URL to a product or it may only contain the path, in which case it will need to be combined with the store URL. Below, we've laid out what the product link would look like for the Started Checkout event from our more common integrations when item is the Alias.
Event Variable Final Tag BigCommerce {{ event.extra.items.0.product.url }} {{ organization.url }}{{ item.product.url }} Magento 1 {{ event.extra.line_items.0.product.key }} {{ organization.url }}{{ item.product.key }} Magento 2 {{ event.Items.0.Product.FullURL }} {{ item.Product.FullURL }} Shopify {{ event.extra.line_items.0.product.handle }} {{ organization.url }}products/{{ item.product.handle }} WooCommerce {{ event.extra.Items.0.URL }} {{ item.URL } Troubleshooting
If using the organization tag and it leads to a broken link:
-
- Navigate to Account > Contact Information
- Go to
- This happens because Klaviyo populates your website URL in the template using the {{ organization.url }} tag, which pulls directly from the URL you have inserted in your account settings. Removing the forward slash (/) in your account settings can resolve this issue.
Step 9: Preview your email
- Check your email template; it should look similar to the one below
- Click the Preview tab on the left-hand side
- Either preview the email directly in Klaviyo (as shown below) or send it to yourself
You can use these same concepts to build out additional dynamic blocks for flows triggered based on different metrics.
Additional resources