Duplicate issue in for loop to display article in product page

Topic summary

A developer is encountering a duplicate display issue when trying to show blog articles on product pages based on matching tags. The problem occurs when an article has multiple tags that match the product’s tags—the article title repeats for each matching tag instead of displaying once.

Proposed Solution:
Another user suggested adding a {% break %} statement after displaying the article title. This would exit the inner loop once a match is found, preventing duplicate displays.

Current Status:
The original poster reported that the suggested fix didn’t work—nothing displays at all now. They suspect the issue may relate to using a multiple-tag system rather than a single-tag approach.

The discussion remains unresolved, with the core challenge being how to display each matching article exactly once regardless of how many tags overlap between the article and product.

Summarized with AI on November 24. AI used: claude-sonnet-4-5-20250929.

Hello everyone,

I have a little problem with my algorithm. I’m trying to display specific articles on a specific product. I am displaying these articles based on the tags on the articles and on the products. But, when I run my code, my article title displays 3 times if I have 3 tags on my article corresponding to 3 tags on my product.

Here is my code:

{% for prodTag in product.tags %}
  {% for article in blogs.guide-dachat.articles %}
    {% if article.tags contains prodTag %}
      <a href="{{ article.url }}">{{ article.title }}</a>
    {% endif %}
  {% endfor %}
{% endfor %}

Thanking you for your advice

You can try the following. I have done a little adjustment to your code.

{% for article in blogs.guide-dachat.articles %}
  {% for prodTag in product.tags %}
    {% if article.tags contains prodTag %}
      {{ article.title }}
      {% break %}
    {% endif %}
  {% endfor %}
{% endfor %}

Thank you for your awnser. Unfortunately, nothing displays. I think I set a one tag system instead of mutiple tags system.