Problem with widget plugin
-
I have made a widget plugin for my website, and it shows in the plugin list but the widget does not get added to the widget list. Here is the code:
plugin.json:
{ "id": "test", "name": "Test", "description": "Test plugin.", "url": "http://example.com", "library": "./lib/plugin.js", "hooks": [ { "hook": "filter:widgets.getWidgets", "method": "defineWidgets", "callbacked": true }, { "hook": "filter:server.create_routes", "method": "addRoutes", "callbacked": true }, { "hook": "filter:widget.render:status", "method": "renderStatusWidget", "callbacked": true } ] }
lib/plugin.js:
function(module) { "use strict"; var Widget = { templates: {} }; Widget.renderStatusWidget = function(widget, callback) { var html = Widget.templates["status.tpl"]; callback(null, html); }; Widget.defineWidgets = function(widgets, callback) { widgets = widgets.concat([ { widget: "status", name: "Server Status", description: "Minecraft Server Status.", content: Widget.templates["admin/status.tpl"] } ]); callback(null, widgets); }; Widget.addRoutes = function(custom_routes, callback) { var templatesToLoad = [ "status.tpl", "admin/status.tpl" ]; function loadTemplate(template, next) { fs.readFile(path.resolve(__dirname, './templates/' + template), function (err, data) { Widget.templates[template] = data.toString(); next(err); }); } async.each(templatesToLoad, loadTemplate, function(err) { if (err) { throw new Error("Error loading templates: " + err); } callback(err, custom_routes); }); }; module.exports = Widget; }(module));
(code tags are all messed up, so excuse me for the half-formatted code)
(this code is taken from nodebb-widget-essentials and edited) -
Just verifying that you activated the plugin and then restarted NodeBB?
-
@psychobunny Yup, activated plugin in admin panel and hit the Restart NodeBB button. (also tried forever restart)
-
I see a couple of syntax errors in your code, can you try this please?
https://gist.github.com/psychobunny/0973296708cdb9f126ed
- you're missing an opening bracket before function right at the top (although maybe you copy paste error)
- you forgot to define async, fs, and path but you use that to pull the templates
-
@psychobunny Still isn't working http://puu.sh/7bll8.png
-
You should be getting error messages when you run it with node app.js, at least I was getting these errors at first when I tried running your code
My guess is maybe your template files aren't uploaded or you're pointing to the wrong path?
-
@psychobunny I was running the version without the opening bracket with node app.js and didn't get any errors, so I guess it's not printing errors or something.
-
Maybe you're running on production? or maybe the error only happens when you attempt to activate the plugin. I got this just from running
node app
and trying to activate the plugin -
@psychobunny Ah, did ./nodebb dev, and look what popped up:
warn: [plugins] Plugin 'mcpartyzone' not found
How would I fix that?
(plugin is called mcpartyzone btw) -
@psychobunny Ah, figured it out, in the plugin.json I called the plugin "mcpartyzone" where it was actually called "nodebb-plugin-mcpartyzone". Now it works, thanks for the help!
-
ahaha okay looking forward to seeing what this mcpartyzone plugin is all about
-
@psychobunny It's a plugin for a Minecraft server website I am developing. (switching over from Enjin)