passing a string is deprecated


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

  • Admin

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

    How should I render a widget html template?


  • Global Moderator

    @zoharm

    widget.req.app.render('widgets/globalstats', renderData, function (err, html) {
      widget.html = html;
      callback(err, widget);
    });
    


  • @PitaJ Worked great. Thank you!


 

Suggested Topics

| |