passing a string is deprecated

NodeBB Plugins
  • Anime Lovers

    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?

  • Community Rep

    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});
  • NodeBB

    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);
  • #4

    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) {
        ...'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 to data.html (in this case, widget.html ?) is not pretty 🙂

    How should I render a widget html template?

  • Global Moderator Plugin & Theme Dev

    @zoharm'widgets/globalstats', renderData, function (err, html) {
      widget.html = html;
      callback(err, widget);
  • #6

    @PitaJ Worked great. Thank you!

Suggested Topics

| | | |