Skip to main content
Solved

How to break a loop

  • July 3, 2023
  • 2 replies
  • 240 views

Forum|alt.badge.img+2

Hello,

 

Here is what I want to achieve: I have a set of SKUs. I want to show a specific block of text only ONCE if the sku is matching one of the skus on my list.

I have this loop created:

{% for product in event.products %} {% for package in product.packages %}

{% if product.sku == '290002' or product.sku == '290003' or product.sku == '290004' %} Show this Text {% endif %}  {% endfor %}  {% endfor %}

But in this case, if there are multiple SKUs matching this search, the text will be shown multiple times. 

How do I make it show only once?

 

Thank you!

Best answer by stephen.trumble

Hey @Nataliia 

Welcome to the community and congrats on your first post!

I would suggest changing the logic to an elif statement. Something like this will achieve your goal:
{% if product.sku == '290002' %} Show this Text {% elif product.sku == '290003' %} Show this Text {% elif product.sku == '290004' %} Show this Text {% endif %} {% endfor %}  {% endfor %}

Hope this helps!

2 replies

stephen.trumble
Forum|alt.badge.img+60
  • Klaviyo Alum
  • 1515 replies
  • Answer
  • July 5, 2023

Hey @Nataliia 

Welcome to the community and congrats on your first post!

I would suggest changing the logic to an elif statement. Something like this will achieve your goal:
{% if product.sku == '290002' %} Show this Text {% elif product.sku == '290003' %} Show this Text {% elif product.sku == '290004' %} Show this Text {% endif %} {% endfor %}  {% endfor %}

Hope this helps!


Forum|alt.badge.img+2
  • Author
  • Contributor I
  • 1 reply
  • July 7, 2023

Thank you!