How show header profile when I go in a particular url

NodeBB Development
  • I want to show the header profile user :

    My purpose is create a new url like "" (this is an example) and when the user goes in this url the forum show him the header profile like in the image.

    In my library.js

    plugin.init = function(params, callback) {
    	var router = params.router,
    		hostMiddleware = params.middleware,
    		hostControllers = params.controllers;
    	router.get('/favourites',  hostMiddleware.buildHeader, controllers.renderFavourites);

    can I create header profile user with some method in "hostMiddleware" variable? Anyone can help me?

  • You can inspect the accounts/info controller to see what data is required in your new route.

    Off-hand, I believe the following are required:

  • @julian I change in the library this:

    router.get('/user/:userslug/favouri' hostMiddleware.buildHeader, controllers.renderFavourites);

    Now I need to create "controllers.renderFavourites" method to handle request so I do this

    var db = module.parent.parent.require('./database'),
    user = module.parent.parent.require('./user'),
    async = module.parent.parent.require('async'),
    helpers = module.parent.parent.require('./controllers/helpers'),
    accountHelpers = module.parent.parent.require('./controllers/accounts/helpers');
    var Controllers = {};
    Controllers.renderFavourites = function(req, res, callback) {
    	var userData;
    		function (next) {
    			accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
    		function (_userData, next) {
    			userData = _userData;
    			console.log("sotto 1");
    			if (!userData) {
    				return callback();
    				history: async.apply(user.getModerationHistory, userData.uid),
    				sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID),
    				usernames: async.apply(user.getHistory, 'user:' + userData.uid + ':usernames'),
    				emails: async.apply(user.getHistory, 'user:' + userData.uid + ':emails')
    			}, next);
    	], function (err, data) {
    		if (err) {
    			return callback(err);
    		userData.history = data.history;
    		userData.sessions = data.sessions;
    		userData.usernames = data.usernames;
    		userData.emails = data.emails;
    		userData.title = '[[pages:account/info]]';
    		userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:account_info]]'}]);
    		res.render('account/info', userData);

    So for example suppose to create a user with slio like username and when this user goes at route /user/slio/favouri, the page that appears is


    Now With jquery I can modify the page according my intentions. @julian is the correct solution?

  • @julian and If I want to load not "account/info " but "account/favourites" ?

Suggested Topics

  • 0 Votes
    3 Posts

    Thanks. Yes it works fine. Only one problem.

    Seems like


    is not called when i refresh the page. It is called only if browse the forum. I noticed it now because i use this hook to capture user counters and put them into the stats page.
    It wont work also with simple code, outside or inside the document-ready function.

    P.S: i just solved using directly

    global variable. It is just a problem of the hook

  • 0 Votes
    2 Posts

    did you activate widget ?

    ACP > Extension > Widget

    Select in right scroll menu the module recent cards.

  • 0 Votes
    3 Posts

    Thank you

  • 0 Votes
    3 Posts

    Thanks, I have just solved the error.

    But the code doesn't work for now. How can I do execute a function when user go to topic?


  • 0 Votes
    3 Posts

    Ya, so I was dumb...I have a local dev instance and a staging server. I was playing around with some things and forgot to switch the theme back to vanilla which explains why I was missing the navbar for the login me.

    But yes, thanks for pointing that out. The template engine and middleware are making a lot more sense now after looking through the source for the last 2 days...

    I'm going to start looking to add/update the documentation here soon...some of the stuff can drive you crazy if you aren't familiar with the version changes.

    Also, after reading through most of core at this point I have to say it's an impressive piece of kit. Thumbs up to the core devs. @julian @baris @psychobunny

    EDIT: Also, anyone else who comes across this thread...if you really want to save yourself some time banging your head against the wall -- like I did -- take a few days to really dive into the nodebb source. It has been a good lesson in object-oriented javascript -- so many objects 🙂 -- done right. I've realized I'm approaching things more from a functional perspective, so this has been an eye opener for me.