How to get the current topic?

Dear community,

at the moment we have the set the blog title like this. This is the standard markup for a HubSpot blog.

<div class="cell-wrapper">
<h1>{{ group.public_title }}</h1>
</div>

However, we would like to add additional information to the content of the <h1> tag depending on the listing view. For example when the user visits topic “X” which filters only the posts for topic “X”. I would like the the topic “X” being displayed in the <h1> tag, in order to give the site visitor a proper information which topic has been selected and filtered.

Is there any HubL tag which can provide me with the current topic? So I can output the content?
Thanks for your support.
Kind regards,

Nhan

Hi @jobnomade,

Yes, this is possible without the use of Hubl code.

We are using in our projects and it’s working fine for us.

Just paste my javascript code in your edit head and it will work!

<script>
$(document).ready(function() {
 var url01 = window.location.href.split("tag/")[1];
 $('h1').text(url01.replace('-',' '))
});
</script>

Hope this work!

| | Did my post help answer your query? Help the Community by marking it as a solution. |
| — | — |

TRooInbound Team

For more help and solutions, please visit at www.trooinbound.com or email at hello@trooinbound.com

Thanks for your response.

This is a nice solution for the user with JavaScript enabled.

However, I wanted to avoid as well duplicated <h1> content and want to insert the topic here for search engines. I have an idea how to solve it with HubL. I will post it here as soon I have done some tests.

Hi @jobnomade,

Yes, We have some investigation and found the solution using Hubl code as well.

so now Our HubSpot Community has Two Solution using HubL code and using Javascript code! Both are working perfectly.

here is HubL code for your problem.

{% if topic %}<h3>{{ page_meta.meta_description|replace(' | ', '') }}</h3>{% endif %}

Hope this work!

Let’s see your solution and discuss!.

| | Did my post help answer your query? Help the Community by marking it as a solution. |
| — | — |

TRooInbound Team

For more help and solutions, please visit at www.trooinbound.com or email at hello@trooinbound.com

@jobnomade,

No need for javascript.

the listing page actually has a variable for topic that is empty when not filtering by topic but is set to the topic filtered when filtering.


You can do this:

<div class="cell-wrapper">
 <h1>
 {% if topic %}
 {{ topic }} 
 {% else %}
 {{ group.public_title }}
 {% endif %}
 </h1>
</div>

that will check if topic exists and if it does it will use the topic instead of the blog title

How would this be done today? the {{ topic }} does not seem to be present on blog listing pages anymore? (it is not in the documentation about available variables either).

@PDeT ,

Might take a look at {{content.topic_list}}

Well, no, that is not set on the topic listing page. It is a property for blog posts.

that variable ‘topic_list’ does not seem to be set on listing pages.