# Custom blog topic page

**URL:** <https://community.hubspot.com/t/custom-blog-topic-page/9512>\
**Category:** CMS Development\
**Created:** [July 18, 2018, 8:21pm UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512 "2018-07-18T20:21:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [July 18, 2018, 8:21pm UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512/1 "2018-07-18T20:21:38Z")

</div>

Hi there!  
I’m creating a custom view for each topic in my blog  
I’m using this code

```auto
{% if is_listing_view %}
 {% if topic %}
 My custom code
 {{topic}}
 {{topic.name}}
 {{topic.slug}}
 {% endif %}
{% endif %}

```

According to the documentation this {{topic}} variable has the topic.name and the topic.slug properties, but it seems it doesn’t work.  
I need this {{topic.name}} for printing the topic name not as a slug but the normal text.  
Do you know what is wrong with this code?

---

<div class="post-metadata">

**Author:** ![Phil\_Vallender](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/phil_vallender/32/48924_2.png) [@Phil\_Vallender](https://community.hubspot.com/u/Phil_Vallender)\
**Post date:** [July 18, 2018, 9:16pm UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512/2 "2018-07-18T21:16:52Z")

</div>

Hi @mateomm22

I’m not a developer so I could be wrong on this, but when I look at the developer info for one our posts, I’m seeing variables in the format ‘topic\_names’ not ‘topic.name’.

Could it be that simple?

---

<div class="post-metadata">

**Author:** ![mateomm22](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateomm22/32/6707_2.png) [@mateomm22](https://community.hubspot.com/u/mateomm22)\
**Post date:** [July 18, 2018, 9:21pm UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512/3 "2018-07-18T21:21:19Z")

</div>

Hi [@Phil\_Vallender](https://community.hubspot.com/t5/user/viewprofilepage/user-id/74)  
I’m afraid this isn’t the solution according to the Hubspot documentation this {{topic}} variable has these two values inside it.  
_“The topic variable can be used to render markup for a topic listing. It also contains the properties: topic.name and topic.slug.”_  
Anyway thank you for the quick response

---

<div class="post-metadata">

**Author:** ![Phil\_Vallender](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/phil_vallender/32/48924_2.png) [@Phil\_Vallender](https://community.hubspot.com/u/Phil_Vallender)\
**Post date:** [July 19, 2018, 6:32am UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512/4 "2018-07-19T06:32:56Z")

</div>

Hi @mateomm22

Ok - we need an expert! @Jsum can you help?

---

<div class="post-metadata">

**Author:** ![JasonRosa](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jasonrosa/32/56551_2.png) [@JasonRosa](https://community.hubspot.com/u/JasonRosa)\
**Post date:** [July 19, 2018, 7:59am UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512/5 "2018-07-19T07:59:03Z")

</div>

Hey @mateomm22 it is possible to print the topic name on the topic page but it is a bit of a workaround. To do it, your code would need to be similar to the [documentation here](https://designers.hubspot.com/docs/hubl/blog-content-markup#if-topic-statement). It would look like this:

{{ page\_meta.html\_title|replace(’ | ', ‘’) }}

If we break down the code, what we’re essentially doing is getting the blog topic page HTML title which is the blog listing page HTML \<title\> followed by a ‘|’ followed by the topic name. Then we’re using the [replace filter](https://designers.hubspot.com/docs/hubl/hubl-supported-filters#replace) to remove the blog listing \<title\> and ‘|’ piece of things so that we are just left with the topic name. So all you have to essentially do is add the blog listing title before the ‘|’ part in the code above. If my blog listing \<title\> was “My Blog 2018” my code would be:

{{ page\_meta.html\_title|replace('My Blog 2018 | ', ‘’) }}

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [July 19, 2018, 11:35am UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512/6 "2018-07-19T11:35:46Z")

</div>

@mateomm22,

I pretty printed the topics variable on my own blog:

` {{ topic|pprint }}`

and the result was:

` (STRING: HUBSPOT-DEVELOPMENT)`

printed to the screen, ‘HUBSPOT-DEVELOPMENT’ being the topic slug as a string.

There are three things you can do with this:

1. Format the slug. use the replace filter to remove swap the '-'s for spaces and use the capitalize filter for… capitalization.

`{{ topic|replace('-', ' ')|capitalize }}`

2. You can use it to check a topics loop:

```auto
{% set my_topics = blog_topics('default', 250) %}

{% for item in my_topics %}

 {% if topic == item.slug %}
 {{ item.slug }}
 {{ item }}
 {% endif %}

 {% unless topic == item.slug %}
 {{ item.slug }}
 {{ item }}
 {% endunless %}
{% endfor %}

```

3. Add the topic slug as a body class. I don’t know if that’s useful, but you can do it.

Need help? [Hire Us Here](https://www.upwork.com/o/companies/_~0124e15ff34efb3871/)

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [July 19, 2018, 11:51am UTC](https://community.hubspot.com/t/custom-blog-topic-page/9512/7 "2018-07-19T11:51:26Z")

</div>

@mateomm22 - Try this HUBL loop instead of the one you currently have. This will loop through all of the topics related to the current page’s blog posts and match the slug to the current page’s slug. Then you can use the name to display on your page.

```auto
{% if is_listing_view %}
 {% for t in contents_tags %}
 {% if t.slug == topic %}
 {{t.name}}
 {% endif %}
 {% endfor %}
{% endif %}

```

* * *

If this answer helped, please, mark as solved 😄

* * *

[tim@belch.io](mailto:tim@belch.io) | [forms.belch.io](https://forms.belch.io) | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me [on slack](http://slack.belch.io/).
