With Express 3.0 the view functionality is slimming down even further. Today
res.render not only integrates with template engines but also introduces the concept of layouts.
The layout option and functionality is being removed in favor of more flexible alternatives that template engines can offer without Express solving it for them.
Jade saw the introduction of the
block citizens. A template now:
- Expresses what layout it belongs to, which is a more natural fit in web applications.
- Declares what blocks it extends, which means a template can add markup to more than one part of the layout.
// my-template.jade extends my-layout block head script(src="myfile.js") block content h1 My page
// my-layout.jade doctype 5 html head title My title block head body #content block content
In addition to “filling” a certain gap in the template, you can leverage the
prepend keywords to have different templates modify others incrementally.
This simplification is a win for everyone.
res.render now just focuses on providing the glue to other modules, your routes will simplify, and understanding what a template ultimately renders is easier.