I am trying to have the render name in my jade
I could do:
app.render('email', { render: 'email' }, function(err, html){
// ...
});
but I'd like to know if there is a solution to get it automaticly
Thanks
I have found it helpful to write a wrapper function around render that takes a response object, a view name, and any additional options. I then use this function exclusively instead of res.render
. My implementation does things like automatically decorating the title, assigning a unique view id to all views, etc. I use it like:
render(res, 'user.new', {title: 'sign up'});
In this example, the function takes the view name 'user.new'
and gives it a unique id: 'user_new_view'
assigned to the body element. In your case you could simply pass the value to your template.
The benefit of this pattern is that a single function acts as an interface to all of your views (assuming you use it consistently), so if you need to change the information passed to your views you don't have to edit every endpoint in your application.