CMS Development

jobnomade
Participant

How to get the current topic?

SOLVE

 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

0 Upvotes
2 Accepted solutions
TRooInbound
Solution
Key Advisor

How to get the current topic?

SOLVE

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

View solution in original post

Jsum
Solution
Key Advisor

How to get the current topic?

SOLVE

@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. 

HubL supported variables.pngYou 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

View solution in original post

0 Upvotes
8 Replies 8
PDeT
Participant

How to get the current topic?

SOLVE

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

0 Upvotes
PDeT
Participant

How to get the current topic?

SOLVE

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).

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

How to get the current topic?

SOLVE

@PDeT ,

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

0 Upvotes
PDeT
Participant

How to get the current topic?

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

0 Upvotes
Jsum
Solution
Key Advisor

How to get the current topic?

SOLVE

@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. 

HubL supported variables.pngYou 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

0 Upvotes
TRooInbound
Solution
Key Advisor

How to get the current topic?

SOLVE

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

jobnomade
Participant

How to get the current topic?

SOLVE

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.

TRooInbound
Key Advisor

How to get the current topic?

SOLVE

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

0 Upvotes