Solved

event.Items issue - square bracket

  • 13 April 2024
  • 3 replies
  • 51 views

Badge +1

Hello everyone,

I'm working on an email template in Klaviyo, and I'm using {{ event.Items|default:'' }} to display a list of items from multiple orders. However, the preview shows the list with square brackets and commas, like this:

How's Your Experience with ['Product 1', 'Product 2', 'Product 3']?

 

I'd like to format this list without the square brackets and ideally add the word 'and' between multiple items, like this:

How's Your Experience with Product 1, Product 2, and Product 3?

 

Can anyone please advise on how to achieve this formatting using Klaviyo? Any help would be greatly appreciated!

Thank you!

icon

Best answer by bluesnapper 14 April 2024, 13:22

View original

3 replies

Userlevel 7
Badge +37

Welcome to the community @laycocupo 

This works and achieves what you want. Add this as a text block as shown. 

<div>
How's Your Experience with
{% if event|lookup:'Item Count' > 1 %}
{% for item in event.extra.line_items %}
{% if not forloop.last %}{{ item.title }}, {% else %}and {{ item.title }}? {% endif %} {% endfor %}
{% else %} {{ event.Items.0 }}?
{% endif %}
</div>

Notes:

  • The reason for the first if’ statement is so the formatting is correct for instances where there’s only one product
  • The first ‘if’ statement checks to see if there is more than one product. If there is, the next few lines loop over the products and adds a comma between them, apart from the last product in the list, which is preceded by ‘and’.
  • If there is only one product, that is displayed without any formatting.
  • You need to enclose the code between <div>...</div> as shown above; otherwise, Klaviyo will insert divs and break the formatting.

Hope that helps

Regards

Andy

Badge +1

Thanks for the warm welcome, @bluesnapper! :)

It works!!! 🎉 I've added the text block as instructed, and everything looks great. Your detailed notes are super helpful for understanding the logic behind the code. I really appreciate your guidance. Looking forward to being part of the community!

-Layco

Userlevel 7
Badge +37

Happy to help @laycocupo and thanks for letting me know it worked for you.

Regards

Andy

Reply