Overwriting controllers in plugin


(Steve Ng) #1

Hi, I wanted to add additionally functionality through a plugin.

I added a topic controller at plugins/xx/assets/javascripts/discourse/controllers/topic.js.es6

and I have

import TopicController from 'discourse/controllers/topic';
export default TopicController.reopen({
   actions: {
      own_actions:function() { debugger; };
   }
});

when I tried to call the action from my topic.hbs template, it says action own_action is not found. is theer anything I would have to do to initialize this controller?


(Alan Tan) #2

Ideally, you’ll want to reopen the controller inside an initializer.

Have a look at the “initialize code” section under Beginner’s Guide to Creating Discourse Plugins - Part 1. :slight_smile:


(Joe Buhlig) #3

If you want another example, take a look at the voting plugin. I do something similar there. It’s not from the controller itself but it’s close.

https://github.com/joebuhlig/discourse-feature-voting/blob/master/assets/javascripts/initializers/feature-voting.js.es6