How add another route with another .tpl file

NodeBB Plugins
  • I need to create another route for show another html result. So I define my new route in my library.js

    plugin.init = function (params, callback) {'/user/plugins/answer/home', controllers.renderTest);

    In controller I have create my method:

    	db.getObject('....', function(err, data) {
    		if (err) { return next(err); }
    		res.render(/user/plugins/test', data);

    My test.tpl page is in /templates/user/plugins and now in my test.tpl page is:


    My plugin.json is:

    	"staticDirs": {
    		"static": "./static"
    	"less": [
    	"scripts": [
    	"templates": "static/templates"

    So I go at the address http://IPADDRESS/user/plugins/answer/home and I see "/user/plugins/answer/home Not Found Not Found" . Anyone can help me?

  • So I go at the address http://IPADDRESS/user/plugins/answer/home

    You've registered a POST route but trying to access it via browser request I assume.
    POST is for sending data to the server, you need a GET route for the default behavior of your browser.

    // replace this'/user/plugins/answer/home', controllers.renderTest);
    // with this
    params.router.get('/user/plugins/answer/home', controllers.renderTest);
  • thanks frissdiegurke I try your solution and It's work but when I go on the link I see the page and the write, but the background is white, i lost the header and the footer of nodebb. Can you suggest something to do for have the background forum and in the center put my .tpl page?

  • As of the source code of nodebb-plugin-custom-pages (which may fit your needs anyways) I assume you just need to add the buildHeader middleware.

    plugin.init = function (params, callback) {
      params.router.get('/user/plugins/answer/home', params.middleware.buildHeader, controllers.renderTest);
  • @frissdiegurke said:

    params.router.get('/user/plugins/answer/home', params.middleware.buildHeader, controllers.renderTest);

    @frissdiegurke thanks!!!! It workss fine!

  • Thanks for providing much needed assistance @frissdiegurke 😄

    Welcome to the land of plugin creation @Doppy !!

Suggested Topics