Sep 29, 2022 2:47 PM
Hi all! I am having an issue where any blog posts that have more than one tag will display more than once. Here is my code:
{% for content in contents|unique %}
{% if loop.index > 1 %}
{% for topic in content.topic_list %}
{% unless topic.name == 'Expert Forum Insider' %}
<article class="blog-index__post blog-index__post--large">
<a href="{{ content.absolute_url }}">
<div class="blog-image-section">
{% if content.featured_image and group.use_featured_image_in_summary %}
<div class="blog-index__post-image blog-index__post-image--large"
href="{{ content.absolute_url }}">
<!-- <picture>
<source srcset="{{ content.featured_image|replace("jpg", "webp") }}" type="image/webp">
<source srcset="{{ resize_image_url(content.featured_image, 380, 0, 0) }}" type="image/jpeg"> -->
<img src="{{ resize_image_url(content.featured_image, 380, 0, 0) }}" alt="{{ content.featured_image_alt_text }}">
<!-- </picture> -->
</div>
{% endif %}
{% for topic in content.topic_list %}
{% unless topic.name == "featured" or topic.name == "featured-main" %}
{% if loop.index < 2 %}
<div class="topic-link">
<span class="topic-style">{{ topic.name }}</span>
</div>
{% endif %}
{% endunless %}
{% endfor %}
</div>
<div class="blog-content-section">
<div class="blog-index__post-content blog-index__post-content--large{% if !content.featured_image or !group.use_featured_image_in_summary %} blog-index__post-content--full-width{% endif %}">
<h3 class="blog-title-name">{{ content.name }}</h3>
</div>
</div>
</a>
</article>
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
Solved! Go to Solution.
Sep 29, 2022 3:38 PM
Yeah it was looping through the topic list. I found this as a solution that worked perfectly...
{% set myString = "Expert Forum Insider" %}
{% if myString in content.topic_list|map('name') %}
{% else %}
Sep 29, 2022 3:11 PM - edited Sep 29, 2022 3:12 PM
{% for content in contents|unique %}
{% if loop.index > 1 %}
{% for topic in content.topic_list %}
{% unless topic.name == 'Expert Forum Insider' %}
Could it be that you are looping the topic_list here as well?
Your loop here is outputting the HTML once for each topic a content has. So if a content has 2 topics, it'll appear twice.
Sep 29, 2022 3:38 PM
Yeah it was looping through the topic list. I found this as a solution that worked perfectly...
{% set myString = "Expert Forum Insider" %}
{% if myString in content.topic_list|map('name') %}
{% else %}