passing a string is deprecated
-
I am totally get confused by the output message:
winston.warn('[widgets.render] passing a string is deprecated!, filter:widget.render:' + widget.widget + '. Please set hookData.html in your plugin.');
There isn't any full example showing the correct way to code.
So I turn the forum for help, is there any people who could give me an example showing how to let the warning not showing? -
Oh! I'm glad they finally made that change. This means you pass back the widget html in an object.
// filter:widget.render:widget exports.renderWidget = function (data, next) { var html = "<b>Awesome Widget</b>"; next(null, {html: html}); }
-
The code @yariplus posted will get rid of the warning. If you somehow have 2 different plugins listening to the same widget hook you should set the html object on the data itself like so.
// filter:widget.render:widget exports.renderWidget = function (data, next) { data.html = "<b>Awesome Widget</b>"; next(null, data); }
-
Apologies for the evil resurrection, just got back into NodeBB after a loooong break
The way I render my widget is as such:
plugin.renderGlobalStats = function (widget, callback) { ... widget.req.app.render('widgets/globalstats', renderData, callback);
This throws the warning this thread is about.
How should I go about fixing this? I assume reading my template file (
widgets/globalstats.tpl
) and assigning it as string todata.html
(in this case,widget.html
?) is not prettyHow should I render a widget html template?
-
widget.req.app.render('widgets/globalstats', renderData, function (err, html) { widget.html = html; callback(err, widget); });