Solved

How to break a loop

  • 3 July 2023
  • 2 replies
  • 81 views

Badge

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!

icon

Best answer by stephen.trumble 5 July 2023, 22:59

View original

2 replies

Userlevel 7
Badge +60

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!

Badge

Thank you!

Reply