Rakesh Tholiya Rakesh Tholiya - 4 months ago 14
Node.js Question

Node js how to create dynamic path

I want path like "left_sidebar/{user_role}"

{{> layout/left_sidebar/(here_user_role)}}


I have user role in session

{{session.passport.user.role}}


So how can i create path like "left_sidebar/admin"

Answer

Try with this

var app = express();
app.set('view engine', 'hbs');
app.engine('hbs', exphbs({
    helpers: {
        role_base_partial : function (path,name) {
            return path + name;
        }
    }
}));

In your View file

{{> (role_base_partial 'layout/left_sidebar/' role_name) }}