Skip to content

Latest commit

 

History

History
80 lines (51 loc) · 3.67 KB

02-plugin-outlet.md

File metadata and controls

80 lines (51 loc) · 3.67 KB
title short_title id
Developing Discourse Plugins - Part 2 - Connect to a plugin outlet
Plugin outlet
plugin-outlet

Previous tutorial: https://meta.discourse.org/t/developing-discourse-plugins-part-1-create-a-basic-plugin/30515


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:

<PluginOutlet @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 <PluginOutlet />. 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 "<PluginOutlet" -- "*.hbs"

@RGJ has also written a theme component to show their locations.

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 the Discourse handlebars template has:

<PluginOutlet @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:

plugins/hello/assets/javascripts/discourse/connectors/evil-trout/hello.hbs

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.

Troubleshooting

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

More information

https://meta.discourse.org/t/using-plugin-outlet-connectors-from-a-theme-or-plugin/32727


More in the series

Part 1: Plugin Basics Part 2: This topic Part 3: Site Settings Part 4: git setup Part 5: Admin interfaces Part 6: Acceptance tests Part 7: Publish your plugin