Get topic id when the topic show page loads

Thanks. I’m familiar with some of the basics you mention, but there’s one point that gets me stuck (and I bet this kind of thing gets a lot of people stuck):

On the topic show page, it loads the template /templates/components/topic-category.hbs. That’s what displays the category and also the tag beneath the topic title.

In topic-category, it lists out topic.tags. So that’s the key piece of info I need to get this going.

Here’s where I am stuck: How can I get that topic.tags information to my javascript?

For example, if I just wanted to console.log the contents of topic.tags, how would I do that?


I know how to override templates. For example, in a theme, I could put in a file at discourse/templates/components/topic-category.hbs, and reprint the template there, adding in changes I wanted to make to the view. (I’m using the separate file structure described here).

In my theme, I also know how to put javascript at theme/initializers/initializer-file.js.es6.

And I can make the two interact with some jquery. For example, I could put the topic.tags into a div in the template, and access that in my initializer with jquery by getting the content of that div.

But that’s round about. How can I get that topic.tags info directly so I can parse it and manipulate it?

1 Like