Skip to main content

We want to enhance our product browse flow by creating branches for specific high volume SKUs. In the email we are only pulling in one product because our customers typical behavior is to browse a lot of products so the email would be too long if we pulled in all of them.

 

We want to create the email for products that include the word “Linen.” The product name is the “event.name” in Klaviyo.

 

I created the branch in the flow using a conditional statement if users browsed a product that contained “Linen”. Now I need to ensure that the Linen product they browsed is the main product we’re pulling in the email. Since many users are browsing multiple SKUS, we want to prioritize the Linen SKU

 

I tried using this and it didn’t work:

{% if ‘linen’ in event.name %}

Show Linen product

{% endif %}

 

Anyone else have ideas?

@lauriecaldwell hey, thanks for posting this!

You’re on the right track but there are two little hiccups along the way, first one being that Klaviyo uses Django for these callbacks (at least that’s my understanding), and the second one being, if someone browses more products than one, Klaviyo will create an Items event, and not just “name”.

The code below should be a solution for your query:
 

{% for item in event.Items %}
  {% if 'Linen' in item.name %}
    {% assign linen_product = item %}
    {% break %}
  {% endif %}
{% endfor %}

{% if linen_product %}
  <!-- Render the linen_product details -->
  <h2>{{ linen_product.name }}</h2>
  <img src="{{ linen_product.image }}" alt="{{ linen_product.name }}">
  <p>{{ linen_product.price }}</p>
  <a href="{{ linen_product.url }}">View Product</a>
{% endif %}

I haven’t tested this in full but give it a go and let us know if it worked!
 


Hi - this did not work.  I tried a few different variations. Any other ideas?


@lauriecaldwell hey, sorry to hear that! Would you mind letting us know a bit more detail, what error did you get, what variations did you try?