help with using helpers inside my theme

  • I managed to make some changes on my template from the client side, but am trying to do the same thing on the server side. I am trying to create a helper. but somehow It doesn't work. here what I have done :
    first I added the hook on plugin. json :
    { "hook": "filter:topics.get", "method": "clAppendTitle" }
    then in library.js I added this code :
    var Benchpress = require.main.require('benchpressjs');

    library.clAppendTitle = function (params, callback) {
    Benchpress.registerHelper('clAppendTitle', function () {
    console.log("inside my filter");

    I am trying to solve this issue for some time now. please someone help ! I am unable to figure out how to create and use helpers. I am using the last version of nodebb.

  • Global Moderator

    So, you need to provide the helpers both server-side and client-side. To do this, you first want to create a module that will work in both contexts:

    // helpers.js
    (function (factory) {
      if (typeof module === 'object' && module.exports) {
      } else {
        require(['benchpress'], factory);
    })(function (Benchpress) {

    Then, you want to require this module in your plugin server-side:

    // library file
    require('./helpers'); // doesn't need to be inside the init hook

    Then you want to make sure it's included client-side by including it under "scripts" in your plugin.json:

      "scripts": [

  • @PitaJ thank you so much!

Log in to reply

Suggested Topics

  • 12
  • 1
  • 1
  • 17
  • 5
| |