Tuesday, 14 March 2017

Express.js handlebars helpers with named-routes

I am building app using Express.js and ended up using named-routes module.

As git readme says, I should be able to use url helper like that:

// in the views:
url('about') // '/about'
url('todo.user.list.id', {user: 'foo', list: 93, id: 1337}) // '/todo/foo/93/1337'
url('todo.user.list.id', {user: 'foo', list: 93}) // Throws error, missing parameters

But I have no idea how to use these helpers in hbs templated file. gives me an error (no wonder - I have no hbs helper registered).

Is there any way I should be able to use these helpers in my views using hbs, or should I define them by myself? For now I registered function helper named route:

 route = (route) => {
  return app.namedRoutes.build(route);
}

But I am not sure if it is correct solution.



via Jakub Kopyƛ

No comments:

Post a Comment