# Hook for a topic's category id?

**URL:** https://meta.discourse.org/t/hook-for-a-topics-category-id/40002
**Category:** Development
**Created:** [February 22, 2016, 7:44pm UTC](https://meta.discourse.org/t/hook-for-a-topics-category-id/40002 "2016-02-22T19:44:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [February 22, 2016, 7:44pm UTC](https://meta.discourse.org/t/hook-for-a-topics-category-id/40002/1 "2016-02-22T19:44:40Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![joebuhlig](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joebuhlig/32/193054_2.png) [@joebuhlig](https://meta.discourse.org/u/joebuhlig)
#### Post date: [February 24, 2016, 3:30pm UTC](https://meta.discourse.org/t/hook-for-a-topics-category-id/40002/3 "2016-02-24T15:30:56Z")

</div>

Here’s how I’m doing it in the [feature voting plugin](https://github.com/joebuhlig/discourse-feature-voting):

[https://github.com/joebuhlig/discourse-feature-voting/blob/master/assets/javascripts/initializers/feature-voting.js.es6#L10](https://github.com/joebuhlig/discourse-feature-voting/blob/master/assets/javascripts/initializers/feature-voting.js.es6#L10)

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

`topic.category.id`

PS. I believe with the [plugin changes](https://meta.discourse.org/t/a-new-versioned-api-for-client-side-plugins/40051), I may have some updates to do to this file.

---

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [February 24, 2016, 10:13pm UTC](https://meta.discourse.org/t/hook-for-a-topics-category-id/40002/4 "2016-02-24T22:13:40Z")

</div>

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`?

---

<div class="post-metadata">

### Author: ![joebuhlig](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joebuhlig/32/193054_2.png) [@joebuhlig](https://meta.discourse.org/u/joebuhlig)
#### Post date: [February 24, 2016, 10:34pm UTC](https://meta.discourse.org/t/hook-for-a-topics-category-id/40002/5 "2016-02-24T22:34:16Z")

</div>

That’s how I’m doing it here:

> [@Discourse Topic Voting](https://meta.discourse.org/t/discourse-feature-voting/40121):
>
> discourse2Summary Discourse Topic Voting gives the ability to vote on topics in a specified category.[[1]](#footnote-173202-1)open_bookInstall Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately. Features To enable it, edit any category, look on the settings tab for the “Allow users to vote on topics in this category” checkbox: Once enabled, a “Votes” item is available in the top menu. The topics in that category can be voted on w…
