CMS Development

Armandas
Member

Topic page topic name not outputing.

Hello,

from the documentation: "{{ topic }} - the topic variable can be used to render markup for a topic listing. It also contains the properties:
topic.name and topic.slug." But it doesnt seem to be the case. I'm getting the {{topic}} variable which is the slug, but other variables, like {{ topic.name }}, i can't get. Is this an issue with hubspot or am i misunderstanding something? The page im trying to output it at is a topic page. Example http://example.com/blog/topic/cars-dogs and i would like to get the name of the current topic im in so "Cars dogs" or whatever you named it. 

0 Upvotes
2 Replies 2
JasonRosa
HubSpot Employee
HubSpot Employee

Topic page topic name not outputing.

Hey @Armandas if you're trying to get the topic name to display on the topic page you'll have to use a bit of a workaround which is noted here (http://designers.hubspot.com/docs/hubl/blog-content-markup#if-topic-statement). So you'd want to use an {% if topic %} statement on the listing page. In between the if and the endif is where you'd put your topic page specific content. If you wanted to pull the name of the topic page you'd want to use: 

 

{{ page_meta.html_title|replace('Your Blog Title | ', '') }}

 

You'd then want to replace the "Your Blog Title" in that with your blog's HTML title. Basically on a topic page, the HTML title of the page is "Your Blog Title | Topic Name". The "| Topic Name" part is generated automatically. The solution above is basically a workaround that removes the first part of the Title and leaves you with the topic name. You can also set that value as a variable and use it multiple times within the {% if topic %} statement if that is easier. For example: 

 

{% if topic %} 

{% set topicName = page_meta.html_title|replace('Your Blog Title | ', '') %} 

<h2>{{ topicName }}</h2>

<p>On the {{ topicName }} page we talk about {{ topicName}}.</p>

{% endif %}

elmo
Contributor

Topic page topic name not outputing.

Hi Jason,

 

It seems you have conflicting HubL documentation on this. The HubL variable reference does state that the topic is a type dict variable, containing attributes name and slug: http://designers.hubspot.com/docs/hubl/hubl-supported-variables

 

So maybe correct that one, if the topic is just a string containing the topic slug?