Question about injecting custom data into all NodeBB pages/templates (including header.tpl)

NodeBB Plugins
  • Howdy,
    I'm trying to inject some custom data into all nodebb pages to make the data available for template rendering and javascript access.

    My current approach is not working, I'm listening to the hook: filter:middleware.renderHeader. My plugin function for the hook is getting called with data that includes data.templateValues and then calls a callback with the data that was passed in:

        hookRenderHeader: function(data, callback) {
          data.templateValues.someTestValue = "hello";
          return callback(null, data);
    1. Should I be able to directly use {someTestValue} in header.tpl and other tpl files?
    2. In browser js, should I be able to directly access:
    3. Is there a recommended approach for injecting data into all nodebb templates and

    Thanks for any help or suggestions!

  • If you want data available on all template renders, you should use the hook filter:config.get, example:

    Plugin.configGet = function (config, next) {
      config.someValue = "Some Data"
      next(null, config)

    Now in any template, including header.tpl, using {config.someValue} will print Some Data

    In the browser, the config values will not be available in but will be in config.someValue

    Note that with this method, the values never change, unless the user reloads. If you need dynamic data on every template, you will need a different method, although I can't think of any use case for this.

  • Thank you @yariplus!!! That's exactly what I was hunting for.

  • Glad I could help! 👍

Suggested Topics