Table of contents

How to check for a particular topic on a blog post

There may be instances where you want to print different markup if a post has a partular topic. For example, you may want to have different markup for featured or promoted posts that can be styled to highlight those posts in a list. You can target posts of a specific topic on HubSpot, using an if statement and the map filter.

Each blog post has an associated dict called topic_list. Within the dictionary, each item has attributes such as name and slug. To check whether our not a specific topic exists within this dictionary, a map filter must be applied to the content.topic_list. The attribute name or slug should be specified as the filter's parameter. 

Within the individual post's markup ot the post item markup on a blog listing listing, you could write the following if statement to check for a particular topic name. Keep in mind that if you map using the slug attribute, topic slugs use dashes instead of spaces.

    {% if 'Featured' in content.topic_list|map('name') %}
        Markup to print, if the topic "Featured" is set as a post's topic.
    {% endif %}