Solved

Django experts - need your help!

  • 22 September 2023
  • 6 replies
  • 138 views

Badge

Hi guys,

 

This is for the Order Confirmation email (Shopify). 

My goal is to use the FOR loop and loop through all the items in the order and check item.variant_title

- If at least one variant_title has any of the following words: 'ebook', 'e-book' etc - display message A. 

- If none of variant_titles has any of those words, display message B.  

 

Important: this has to display only one message - A or B, no matter how many items are in the order. But NOT one message per every line item. So that's why I am using the "with" operator here and the if/else conditions. 

 

The code looks fine, but Klaviyo gives an error, maybe something is not supported?

Thanks!

{% with contains_physical_book = False %}
{% for item in event.extra.line_items %}
{% if 'e-book' not in item.variant_title|lower and 'ebook' not in item.variant_title|lower and 'audiobook' not in item.variant_title|lower and 'audio book' not in item.variant_title|lower %}
{% with contains_physical_book = True %}
{% endwith %}
{% endif %}
{% endfor %}

{% if contains_physical_book %}
Message A
{% else %}
Message B
{% endif %}
{% endwith %}

 

icon

Best answer by Omar 26 September 2023, 11:57

View original

6 replies

Userlevel 7
Badge +60

Hi there @leonts,

 

Welcome to the Community! Happy to help!

 

Do you mind sharing ​​​​​​what tempalte error you’re seeing? That could help us better diagnosis the issue! I’d also recommend checking out our  troubleshooting email template error messages documentation to learn more about why you’re seeing this error.

 

Thank you for participating in the Community!

-Taylor

Badge

@Taylor Tarpley hi, thx for your reply.

 

I mean just a typical syntax error.

 

Message displayed without tags or variables

Fix invalid template tags or variables to preview the message with actual profiles and events.

Userlevel 7
Badge +44

@leonts The best way to troubleshoot this would be to simplify the coding first.

Remove all variations and start with one word first and see if that works. Start simple and expand on it. Also just asking, not sure if you also sell other books but maybe a contains book might be the simplest one to catch all. 

Where will you display this message? within the productblock or above/below it as a separate block?

 

@Taylor Tarpley I think this is also valuable feedback I've also ran in, it would be good that whenever we get an invalid template tag that Klaviyo actually outputs which tag that is. I've had to do a lot of troubleshooting from time to time to even be able to find where the issue was.

 

 

Omar Lovert // Polaris Growth // Klaviyo Master Platinum Partner

We help with e-commerce growth through CRO, Klaviyo and CVO

Userlevel 7
Badge +60

Hi there @leonts

 

@Omar gave some great troubleshooting tips here to optimize, and also brings up a great point, I will make a feature request!

 

-Taylor 

Badge

Hi guys @Omar @Taylor Tarpley 

 

Thanks for your help! 

Badge +3

Hi @leonts ,

Were you able to figure out the correct syntax to display only one message - ‘A or B, no matter how many items are in the order. But NOT one message per every line item’?

I am working on troubleshooting a similar issue, my if/else condition related to an item product tag can be true for multiple items in an order, but I’d like my message to display only once, even if the condition is met more than once. Currently my message is repeating for each item. I’m curious what syntax structure worked for you?

Thanks!

Reply