How to build dynamic blocks in a flow email (classic editor)

Last updated at:

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


The steps for creating a dynamic block are as follows: 

  1. Create your flow
  2. Add a dynamic table
  3. Capture the event variable
  4. Establish a data source
  5. Include the product title
  6. Add an image
  7. Show the quantity and total for the product (optional)
  8. Link to the product page (optional)
  9. 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.

 A flow setup for an abandoned cart flow

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

  1. Drag a table block into your email
  2. Delete the third column and column headers within the block columns as well as the divider, which can be adjusted under theBlock Styles tab
  3. Go to Rows
  4. 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

  1. Go into Preview tab to pull up the available dynamic variables
  2. 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 sample event data, the different elements of the variable name are highlighted

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

  1. Click Data Source
  2. Replace Items in the Row Collection field with he variable array you want to repeat (e.g., event.extra.line_items)
  3. Leave item as the Row Alias

A table block is set to dynamic, with its Row Collection and Row Alias filled in

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.

  1. Navigate to one of the columns.
  2. Click on the column where you want the text
    • In this case, we want the text on the right, so choose Column 2
  3. Paste in the full event variable; for instance: {{ event.extra.line_items.0.product.title }}
  4. 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 }} 
  5. 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 

The item title variable in a table block

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.

  1.  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 }}
  2. 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
  3. Change the column to Image
  4. Choose Browse and then select Placeholder
    The placeholder/dynamic image field in the email editor
  5. Input the image event variable, replacing the collection and following number with the alias
    1. For this example, {{ event.extra.line_items.0.product.images.2.src }} becomes {{ item.product.images.2.src }}
    2. Do not remove the number near the end (e.g., the 2 before src)
    3. Click Save
      Dynamic image with variable.jpg
    4. Check the Fill Image Area checkbox and set the pixel size (
      • 250 px is good in most cases
        A dynamic variable is added to the placeholder field
    5. Click Save
    6. 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


    1. Navigate back to the column where you added the product title (e.g., Column 2)
    2. Type “Quantity:” in the text box
    3. Navigate to the preview window to find the event variable 
      • Example: {{ event.extra.line_items.0.quantity }}
        In some sample event data, the item quantity variable is selected
    4. Exit the preview window
    5. Paste the variable next to “Quantity”
    6. Replace the collection and number with the alias 
      1. Example: {{ item.quantity }}


    1. Navigate back to the column where you added the product title (e.g., Column 2)
    2. Type “Total:” in the text box
    3. Navigate to the preview window 
    4. Use the line_price event variable to show the total price of a product based on the quantity
      1. Example: {{ event.extra.line_items.0.line_price }})
      2. For instance, if you have a lipstick that costs $12, and someone has added two of them, the line price will show as $24
        In sample event data, the item price variable is selected
    5.  Paste the variable next to “Quantity”
    6. Replace the collection and number with the alias
      1. Example: {{ item.line_price }}
    7. 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 %}

    Note that the currency format tag cannot be used with the float format filter.

    All dynamic variables have been added to the text field of a dynamic table block

    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

    1. Open the preview window
    2. Locate the event variable for the product handle
      In sample event data, the product's URL handle is selected
    3. Navigate to the column with the image (e.g., Column 1)
    4. Paste the event variable in the field for Link 
      • Example: {{ event.extra.line_items.0.product.handle }}
    5. Replace the collection and number with the alias
      • Example: {{ item.product.handle }}
    6. Include the following before the variable you just added
      1. A link to your store
      2. OR
      3. {{ organization.url }}
        • If you use this tag, set your link protocol to <Other> instead of http or https
          The product URL has been added to the link URL field of the product image
    7. 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 }


    If using the organization tag and it leads to a broken link:

      1. Navigate to Account > Contact Information
      2. Go to 
      3. 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

    1. Check your email template; it should look similar to the one below
      An abandoned cart message is ready to be previewed
    2. Click the Preview tab on the left-hand side
    3. Either preview the email directly in Klaviyo (as shown below) or send it to yourself 
      In the preview tool, sample event data is populated into this dynamic template

    You can use these same concepts to build out additional dynamic blocks for flows triggered based on different metrics.

    Additional resources

Was this article helpful?
278 out of 529 found this helpful