View models

Given a single HTML view in our app, we need to be able to attach data to that page so that the template that is being rendered can be included in such a way that the dynamic areas of the page are replaced with real content. To do this, we need to generate a view model. During the render, the template engine will parse the template itself and look for special syntax that indicates that specific sections should be replaced at runtime with values from the view model itself. Think of this as a fancy runtime find and replace of your HTML templates—finding variables and replacing them with values stored in the view model sent to the template.

A view model, in the sense of how we are using one, is typically just a single JavaScript object ...

Get Web Development with MongoDB and Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.