[WIP] List of all the hooks in Discourse

(Régis Hanol) #1

Here’s the up-to-date list of all the hooks available in Discourse:

Client-side (javascript)


Event triggered by the TopicFooterButtonsView when rendering the buttons at the bottom of a topic.

How to use it? Read the How to add a button at the end of a topic? tutorial.


Event triggered by the TopicMapContainerView when rendering the topic map and any relevant information underneath the first post of a topic.

How to use it?

 onAppendMapInformation: function(container) {
   // your code


Event triggered by the PostView when a post is inserted into the DOM.


Event triggered by the ComposerView when the composer’s preview renders.

Discourse.TopicRoute / setupTopicController

Event triggered by the TopicRoute when a topic is being loaded.

How to use it?

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

Discourse.ApplicationRoute / activate

Event triggered when the ApplicationRoute is activated. This is useful if you need to do something like create a modal once the application has loaded (activated).

Discourse.PageTracker.current() / change

This event is triggered when the current “page” changes. This is useful if you want to hook into an analytics or tracking package:

Discourse.PageTracker.current().on('change', function(url) {
  console.log('the page changed to: ' + url);


Dialects are Discourse’s way to extend our text rendering engine. They are made up of two stages. The first runs functions against the input to emit a JsonML intermediate representation. The second stage post-processes the JsonML before it is rendered to the string.

If you are interested in a custom text processor, you will probably find the functions in dialect.js useful and well documented. There are also examples of using the dialect API in the dialects directory of discourse.


The parseNode hook is for looping through the JsonML tree and modifying it in place. It will be called once per node in the tree so try to keep your function light and fast.

Discourse.Dialect.on("parseNode", function(event) {
  var node = event.node,   // current node in the tree
      path = event.path;   // depth path to the current node

  // your logic goes here. 

Server-side (ruby)


Event triggered by the PostCreator when a post is about to be created.

How to use it?

class Plugin < DiscoursePlugin
  def setup

  def before_create_post(post)
    # your code...

Are Discourse callbacks using Ember or Rails that can be hooked into for plugins?
Help with custom javascript for manual banner ads
A list of server-side functions for weekend/novice Discourse developers?
Current PageTracker.current?
How do you force a script to refire on every page load in Discourse?
How to prevent effects of async loading vs direct loading?
(Kasper Peulen) #2

I noticed that this event is not triggered when I open a topic from an external link. Is this meant to be like this ?

(Kane York) #3

New hook:

Event triggered by the ApplicationRoute when (…?)

(Robin Ward) #4

Thanks I meant to document that above but forgot. (I just did.)

(Tuan Anh Tran) #5

once i found the node i want to modify, example it’s the content at node[1] but when i set node[1] to sth else, it doesn’t seem to get replaced in the editor.

could u help me debug this?

(Kenny Meyer) #6

I wonder if there’s a hook for “Notification creation” - something in the sense of: after_create_notification ?

(Andrew Roth) #7

It would seem that Discourse.TopicRoute is null. Was it replaced by something else?

(Andrew Roth) #8

I figured it out by searching some of the existing plugins. Looks like this line is required before it:

import TopicRoute from 'discourse/routes/topic';