Hook for a topic's category id?

(Steven Slade) #1

I’m looking to get a topic’s category id to use in javascript. Since this info is already being pulled to grab the category tag in each topic for handlebars, I was wondering if I could use that somehow?

A likely helpful piece of code could be this:

Discourse.TopicRoute.on("setupTopicController", function(event) { // Access the controller via: event.controller // Access the model via: event.currentModel });

Can anyone help me with this?

(Joe Buhlig) #3

Here’s how I’m doing it in the feature voting plugin:


You get the topic first and then (if I remember correctly) you can do this:


PS. I believe with the plugin changes, I may have some updates to do to this file.

(Steven Slade) #4

Thanks for this @joebuhlig. So you think if you reopen the TopicRoute, we should be ble to get the topic with var topic = this.modelFor('topic'); and then the rest with topic.category.id?

(Joe Buhlig) #5

That’s how I’m doing it here: