Templating in Express
A fundamental part of the Express framework is its use of views. A view is simply a file that holds template code. Express helps us to separate our code into operationally distinct concerns. We have server code in app.js
, route-specific functionality in routes/index.js
, and then we have our output-generating logic in the views
folder. A template language provides the basis for defining dynamic logic-driven content, and the template (or view) engine converts our logic into the final HTML, which is served to the user. In this recipe, we'll use Express' default view engine, Jade, to process and present some data.
Note
In the There's more... section, we'll find out how to change the view engine.
A list of supported template engines can be found at https://www.github.com/visionmedia/express/wiki. Comparisons of various template engines can be found at http://paularmstrong.github.com/node-templates/.
Getting ready
For our data, we'll use the profiles.js
object created in the first...