"For block" not populating due to double loop

  • 26 October 2021
  • 3 replies

Badge +1


I am creating transactional emails and attempting to create a “for block” where the refunded items & qty populate. 

I tried to use this syntax: {% for item in event.extra.refunds.refund_line_items %}{{ }}  × {{ item.quantity }}{% endfor %}


However it did not work. I also tried incorporating repeat block feature:

Repeat for: event.extra.refunds

Item Alias: item


For block;

{% for item in refund_line_items %}{{ }} × {{ item.quantity }}{% endfor %}


The original syntax for one item is {{ }}.


I am using a Shopify integreation




Best answer by danimclean 2 November 2021, 22:26

View original

3 replies

Userlevel 6
Badge +51

Hi there @danimclean,

Welcome to the Community! Thanks for writing in regarding transactional emails and I hope to work with you to resolve this issue you are facing.

First, in the Repeat Block settings, I would suggest adjusting the "Repeat For" and "Alias" strings to the following:


When deciding what to put in the "Repeat For" box, we consider the name of the attribute we want to repeat, and write the part of the name that comes before the number.  For example, the items in the event have the names event.Extra.Items.0event.Extra.Items.1event.Extra.Items.2, etc.  We therefore put event.Extra.Items under "Repeat For", and we give it any alias we want. I chose the alias item.  

Now, we need to fill out the content of the text block.  The screenshot below shows how I did it:


This is where we make use of the alias item.  Notice, for example, that instead of giving the SKU as event.Extra.Items.0.Product.SKU, I simply used item.Product.SKU.  We want this block to repeat for every item your customer purchased, so we don't want to put event.Extra.Items.0 here, which refers to just the first item.  Instead, we use the alias item, so that every time this block appears in the email for an item, it shows that particular item's SKU.

Following these steps should help with your transactional email form! But is this what you wanted to achieve?

Do you want to pass an event data array to trigger emails and loop through this data? A majority of the time this goal can be accomplished easily by using our track API. We would also like to reiterate that the template API endpoint is meant to be used for testing purposes only and that it is a rate limited endpoint (the figures can be found in the Render template and send email endpoint description in the API docs).

Using the track API will let you pass event data to Klaviyo, which you can then make use of to trigger automated emails. Here is the Klaviyo API reference guide. You would make these emails using our drag and drop template editor or custom HTML and then loop through data using a dynamic block

Some advantages of using the track API include:

Emails can be marked as transactional
You will get access to analytics and advanced reports on your email sends
You can segment profiles based on the event data
You can send automated emails using Flows

None of this would be possible via the templates API.


I hope you found this helpful!


Badge +1

I used this to resolve my issue: {% for item in event.extra.refunds %}{% for refund in item.refund_line_items %}{{ refund.quantity }} x {{ }}<br />
{% endfor %} {% endfor %}

Userlevel 6
Badge +51

Glad to hear you found a solution @danimclean !