Displaying Only Unique Topics in For Loop

tstrack
Contributor

I'm using a for loop to gather topics from all blog posts and populate those topics in a select element. I'm currently seeing duplicates due to the same topics across multiple blog posts. Here is my code:

<!-- Services Filter -->
<select class="select-filter" data-filter-group="services">
  <option value="*">Services</option>
  {% for content in contents %}
  {% for topic in content.topic_list %}
  <option value=".filter-{{ topic.name|lower|replace(' ','-') }}">{{ topic.name }}</option>
  {% endfor %}
  {% endfor %}
</select>

I see that there is a HubL filter for unique. I tried a few things but didn't have any luck. How would I incorporate the unique filter so there are no duplicate topics in my select element?

0 Upvotes
1 Reply 1
roisinkirby
HubSpot Product Team

Hey @tstrack could you share a link to the page(s) you are working on? @dessery is this something you have acheived before?

0 Upvotes