Closed reliasn closed 7 years ago
I ended up writing a plugin that creates another route and renders my template with the user data:
"use strict";
var plugin = {},
db = module.parent.require('./database');;
plugin.init = function(params, callback) {
var app = params.router,
middleware = params.middleware,
controllers = params.controllers,
helpers = module.parent.require('./routes/helpers');
var Forum = db.client.collection('objects');
helpers.setupPageRoute(app, '/subscribe', middleware, [], function(req, res, next){
Forum.findOne({_key: req.uid}, function(err, data){
res.render('subscribe.tpl', {user: data})
})
});
callback();
};
module.exports = plugin;
I suppose nodebb-plugin-custom-pages was made for static pages, but it would be great if it could have some extra features that could turn the content more dynamic.
The idea is to allow us to create custom pages with the user's info:
I'm struggling a little to figure out how data is being passed when you call res.render, but anyways, the above fails because {user} isn't available, while {config} is. So the workaround that I managed to implement was this one:
This seems to work because
header.tpl
has this:which adds the user info to the
app
variable.Is this workaround the only solution considering how this plugin is implemented or am I missing something?