New Route For Home Page



  • HI guys.. im looking over nodebb code so i could have a clue how to write down a plugin that can retrive all categories and recent topics.

    I found the the methods that return that data..

    Categories.getAllCategories
    Topics.getLatestTopics
    

    also found the hook to the homepage

    filter:homepage.get
    

    i was thinking about adding another register on this filter for a custom route but how i can create another route without messing around the core code, and return a json array with those 2 methods return?

    any leads or maybe this idea is too much and there is something more elegant and simple? 🙂


  • Admin

    In your plugins init method you can do

    var helpers = module.parent.require('./routes/helpers');
    
    myPlugin.init = function(params, callback) {
        helpers.setupPageRoute(params.app, '/', params.middleware, [], myCustomHome);
        callback();
    };
    
    function myCustomHome(req, res, next) {
        async.parallel({
             categories: function(next) {
                Categories.getAllCategories();
             }
             topics: function(next) {
                Topics.getLatestTopics();
             }
        }, function(err, results) {
             res.render('myCustomTemplate', results);
        });
    }
    

    I left out some of the params for the 2 methods you mentioned. Let me know if you can't figure it out.


 


Star

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.