How to repeat a block based on dynamic data (classic editor)

Last updated at:

You will learn

Learn how to use the block repeat feature to insert a single block that will automatically repeat itself and iterate over all entries within a single variable. To turn on this block repeat feature for a given block, click the gray hamburger icon at the very top of a block.

If you are unfamiliar with using event variables in emails, check out our guide on how to personalize flow emails with dynamic event data as a first step.

Are you using Klaviyo’s new template editor? Head to our new editor resource center.

Why use the block repeat feature

When you click this icon, a small window will pop up that prompts you to specify an event variable to "loop over" (i.e., repeat), as well as an alias you can use in your template.

In the example below, you will see there are three items in the previewed order:

The variable for the "Blue" item is {{ event.Items.0 }}

The variable for the "Klaviyo Green Tee" item is {{ event.Items.1 }}

The variable for the "Purple" item is {{ event.Items.2 }}

Classic editor event data in the Klaviyo previewer

So, what happens if you want to iterate over all items in an order, and not just include a variable for a single line item? There are two ways to approach this:

  1. Use the block repeat feature available within the template editor.
  2. Build a dynamic table in your template.

Here, we're going to explore how to achieve this with the block repeat feature. Keep in mind that this is just one example use case. You can use this block feature to iterate over any variables that have multiple entries.

How to use the block repeat feature

In the example above, you see that we have:

  • {{ event.Items.0 }}
  • {{ event.Items.1 }}
  • {{ event.Items.2 }}

The variable itself is event.Items and we want to loop over this variable so that event.Items.0, event.Items.1, and event.Items.2 will populate in our template.

In this example, the Repeat For variable is event.Items.

We can then assign this an alias - let's assign the alias as item. Then, we can say, loop over every "item" in  event.Items.

A Klaviyo repeat block's settings 
After clicking to turn this block feature ON, and clicking Save, you will see the feature icon change to gray.

We can then insert the variable alias {{ item }} into this text block and save it. When you preview your template, you will see that all value entries will populate as the specified variable are looped over. 

While this alias will appear as {{ item }} in your template, when you preview the email, it will look something like this:

An email preview with dynamic data

Bear in mind that you can format these variables however you'd like, as well as include additional variables using the same process.

One thing to note is that it's important to only place the variables you want to loop over within the text block that has the block repeat feature enabled. In the above example, the text "We saved all of the great items...simply complete your purchase." is separated into a different text block so that it only displays once, and doesn't repeat along with the variables.

Additional resources

Was this article helpful?
57 out of 115 found this helpful