- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
blog_tags function to get only certain tags
SOLVEAug 28, 2019 4:45 PM
Hi there, is there a way to only select certain tags from the call
blog_topics
I am trying to build a dropdown menu of blog tags.
One with all tags using
{% set my_topics = blog_topics('default', 250) %}
and one with only 3 specific tags
Can I select only certain topics with the same function above? Is there a workaround for this?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Oct 21, 2019 7:41 PM
Hi @kenwhm,
Glad that's working for you. I think if you wanted to, you could simplify your code a bit. You could just write a reverse of the condition and then skip your else statement. In HubL we can get the inverse of an expression with the "not" or "!" operators. So either of these I think would do the trick for you:
{% set my_topics = blog_topics('default', 250) %} {% for my_topic in my_topics %} {% if !(my_topic.name == "Digital Transformation" || my_topic.name == "Retail" || my_topic.name == "Fleet Services") %} {{my_topic.name}} {% endif %} {% endfor %}
or:
{% set my_topics = blog_topics('default', 250) %} {% for my_topic in my_topics %} {% if not (my_topic.name == "Digital Transformation" || my_topic.name == "Retail" || my_topic.name == "Fleet Services") %} {{my_topic.name}} {% endif %} {% endfor %}
This way we're looking to see if the topic name is any of "Digital Transformation", or "Retail", or "Fleet Services". Then we're inversing the result. So if the tag is one of those, we'll reverse it so that the condition evaluates to false and that tag doesn't get printed. If the tag isn't one of those selected, we inverse the condition so that it evaluates to true and print the tag.
I hope that helps!
Leland ScanlanHubSpot Developer Support |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content