Beginner's Guide to Creating Discourse Plugins Part 2: Plugin Outlets


(Robin Ward) #1

Make sure you read the first part of the tutorial before this one, it will help a lot!

Getting Started: Handlebars Templates

Discourse’s client application is written using the Ember.js Javascript framework. Ember uses Handlebars for all HTML templates. There’s a great introduction to the templating language at that link, so definitely read it thoroughly.

The Problem: Adding elements to the Discourse User Interface

Many plugins need to add and extend the Discourse web interface. We provide a mechanism to do this called plugin outlets in handlebars templates.

If you browse the discourse handlebars templates, you’ll often see the following markup:

{{plugin-outlet name="edit-topic"}}

This is declaring a plugin outlet called “edit-topic”. It’s an extension point in the template that plugin authors can leverage to add their own handlebars markup.

When authoring your plugin, look in the discourse handlebars templates (in .hbs files) you want to change for a {{plugin-outlet}}. If there isn’t one, just ask us to extend it! We’ll happily add them if you have a good use case. If you want to make it easier and faster for us to do that, please submit a pull request on github!

If you want to see some of the places where plugin outlets exist, you can run the following command if you’re on OSX or Linux:

$ git grep "plugin-outlet" -- "*.hbs"

@Mittineague has also written a plugin to show their locations. I have to admit I have not tried it out myself so I’m not sure if it works, but it looks like it could be useful!

Connecting to a Plugin Outlet

Once you’ve found the plugin outlet you want to add to, you have to write a connector for it. A connector is really just a handlebars template whose filename includes connectors/<outlet name> in it.

For example, if your handlebars template has:

{{plugin-outlet name="evil-trout"}}

Then any handlebars files you create in the connectors/evil-trout directory
will automatically be appended. So if you created the file:


With the contents:

<b>Hello World</b>

Discourse would insert <b>Hello World</b> at that point in the template.

Note that we called the file hello.hbs – The final part of the filename does not matter, but it must be unique across every plugin. It’s useful to name it something descriptive of what you are extending it to do. This will make debugging easier in the future.


  • Double check the name of the connector and make sure it matches the plugin name perfectly.

  • When in doubt, rm -rf tmp and start your development server again.

More in the series

Part 3: Site Settings

Beginner's Guide to Creating Discourse Plugins Part 3: Custom Settings
Beginner’s Guide to Creating Discourse Plugins Part 6: Acceptance Tests
Beginner's Guide to Creating Discourse Plugins Part 4: Git Setup
Beginner's Guide to Creating Discourse Plugins - Part 1
Problems adding custom button to discourse
Header Menu not showing in sequence
Custom User fields on Usercard
Allow reply-to individual instead of topic/forum (mailing list feature)
Important changes to Plugin Outlets for Ember 2.10
Beginner's Guide to Creating Discourse Plugins Part 5: Admin Interfaces
Topic List Previews
Able to use the 'extraNavItem' custom html outlet?
Rails Girls 2015 SoC Banter
(Kenny Meyer) #2

Is there a list of plugin outlets?

More specifically I would like to know if one could modify the “create topic” template?

(cpradio) #3

In what way? Add new fields to the composer area (like the tagging plugin does)?

(Kenny Meyer) #4

Yes, that’s what I am searching for.

(Robin Ward) #5

I’d take a look at the tagging plugin then. It might have all you want!

(Andrew Byrne) #6

@eviltrout is there a way to output directly to JSON.
basically creating a new API endpoint?

(Andrew Byrne) #7

Ahhhhhhhh. new to this whole “ruby fad” :smiley:
I have a partial solution that i’ll detail in:

(Andrew Roth) #8

Hi Robin,

The plugin-outlet-locations plugin seems to declare all the connectors with a register_asset line in plugin.rb. Starting here: discourse-plugin-outlet-locations/plugin.rb at master · Mittineague/discourse-plugin-outlet-locations · GitHub

Is that a necessary step?

(Robin Ward) #9

Nope - that’s not necessary. All .es6 and .hbs files are loaded automatically in plugins.

(Ilias) #10

I am still trying to figure out how plugins in Discourse work and I could use a little help.

I would like to modify the timeline scroll bar (in the right side of each topic). Actually, what I need to do is add some stuff (image/banner) below the scroll bar.
What template should I edit? Is there an existing plugin-outlet for that?

Thank you,