I tell you my problem I have a blog with different categories (tag / topics) and on the sidebar of the post template I need to put a different image according to the category to which they belong. So far no problem, with the "for topic" and the "if", "elif" and "else" the image I want is shown, the problem comes when a post has more than one assigned category that shows several images and only I want one.
I believe what you can do here is to first get the count of the total topics and you can do so like this:
{% if content.topic_list %}
{% set topic_index_count = [] %}
<p id="hubspot-topic_data" > Topics:
{% for topic in content.topic_list %}
{% if topic_index_count.append(1) %}
<a class="topic-link" href="{{ group.absolute_url }}/topic/{{ topic.slug }}">{{ topic.name }}</a>{% if not loop.last %},{% endif %}
{% endif %}
{% endfor %}
<p> Topic Count: {{topic_index_count|length }} </p>
<p>
{% endif %}
In this case, you can go ahead and modify your code to place another if/else loop after the for loop to check if topic_index_count|length > 1 then display one image.
Hope this helps and do let me know if there's any further question on this!
I believe what you can do here is to first get the count of the total topics and you can do so like this:
{% if content.topic_list %}
{% set topic_index_count = [] %}
<p id="hubspot-topic_data" > Topics:
{% for topic in content.topic_list %}
{% if topic_index_count.append(1) %}
<a class="topic-link" href="{{ group.absolute_url }}/topic/{{ topic.slug }}">{{ topic.name }}</a>{% if not loop.last %},{% endif %}
{% endif %}
{% endfor %}
<p> Topic Count: {{topic_index_count|length }} </p>
<p>
{% endif %}
In this case, you can go ahead and modify your code to place another if/else loop after the for loop to check if topic_index_count|length > 1 then display one image.
Hope this helps and do let me know if there's any further question on this!