Beginner's Guide to Creating Discourse Plugins - Part 1


(Sudaraka Jayathilaka) #87


Is this url correct? Shouldn’t this be ,

I’m new here. please correct me if im wrong :slight_smile:

(Vinoth Kannan) #88

In Discourse, mainly there are two big JavaScript sections “discourse” and “admin”. Also you can see few more in discourse/app/assets/javascripts at master · discourse/discourse · GitHub.

In plugins, to differentiate admin & normal user section JavaScript files we use “discourse” and “admin” keywords in between like below


Also it will just work even without identification keywords like you mentioned :slight_smile:

(Sudaraka Jayathilaka) #89

@vinothkannans Thank you a lot for the explanation. :slight_smile:

(kaja santro) #90

our JS doesn’t seem to work, although we followed every step precisely. We neither have a modal popping from our basic-plugin nor any console.log visible when we pass one :cry:

ideas anyone?

(David Taylor) #91

Difficult to help without being able to see what you’ve got so far. Can you post a link to a github repo showing what you’ve got?

(kaja santro) #92

We found the mistake! Before restarting the rails server, we deleted the temporary files first with $ rm -rf tmp and suddenly it worked.

(Robin Ward) #93

Good to know! I’ve added a reminder piece of text after asking people to restart the server to see the “My changes weren’t picked up” heading if things aren’t working. Hopefully that will help future people avoid getting stuck.

(Clay Heaton) #94

I was having trouble with Discourse seeing the plugin when I used a symlink (on MacOS High Sierra). I deleted the symlink and moved the plugin folder into the Discourse hierarchy and everything worked as expected. Maybe this will help others who run into a similar issue.

(Robin Ward) #95

It should work in High Sierra with a symlink (I use High Sierra at home). I’m not sure why you needed to do the above!

(Clay Heaton) #96

I’m not sure what the issue was. I double-checked the permissions for access and execution of the folder & all looked good when I examined permissions from within the VM. I deleted the tmp directory multiple times but nothing worked until I moved the plugin folder into the discourse directory.

(Sam Saffron) #97

On Linux when I do this the file watcher does not work so bin/rake autospec is less useful. Not sure if kqueue is better here and still notifies.

(Cheng Zheng) #99

It work! 2018-4-28.:grin:

at first it doesn’t work(the alert box don’t come out),
I just delete entire tmp/ folder as some comment suggest.
and then it work perfectly!

1. Code

2. Result

it pop up every time I refresh the page


(Jordan Smith) #100

I tried this guide and it worked, but I just don’t know what’s the relationship between the basic-plugin/plugin.rb and the alert.js.es6 ? What’s the point to make this happen with the file ‘plugin.rb’?

(Mittineague) #101

Hi Jordan_Smith welcome to the forum

My abridged unofficial explanation is that the plugin.rb file “sets things up” for serverside Ruby and allows it’s presence to display in the Admin -> Plugins page.

True, for something as trivial as an “alert”, perhaps a plugin is overkill and it would be better done using Admin -> Customize instead. Just as some things might be better done in a Theme.

I believe the intent of this topic was to provide a simple example to introduce beginning plugin authors to how plugins work, with the hope that it would be only a starting point.

(Jordan Smith) #102

Thank you for the reply. I didn’t question why plug.rb is there. What I wanted to know is how the plug.rb works with alert.js.es6 ? What’s the logic relation between these two files?

(Mittineague) #103

For a more complex plugin there would of course be a lot more going on. But in this example basically all the relation does is associate the JavaScript code with the plugin. Kind of like “If this plugin is installed, then include the JavaScript when the assets are compiled”.

(cpradio) #104

To expand on what @Mittineague has stated, it doesn’t. plugin.rb in the given example only exists because that is what is needed to tell Discourse what the plugin’s name is. description, version, and author. The plugin at this stage, is purely a JavaScript “enhancement” and doesn’t need any ruby code. Once you need ruby code to create new routes/endpoints, alter guardian gates, add SSO functionality, then plugin.rb becomes more than just a “file that tells discourse its name, description, version, and authors”