Book Image

Web Development with MongoDB and NodeJS Second edition

Book Image

Web Development with MongoDB and NodeJS Second edition

Overview of this book

Table of Contents (19 chapters)
Web Development with MongoDB and NodeJS Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
12
Popular Node.js Web Frameworks
Index

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. We have seen examples of this while we explored the Handlebars template framework in the previous chapter. 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. It is important to note that this process happens at the server and the result is only sent as the response to the HTTP request that our application receives.

A view model is typically just a single JavaScript object that can be passed to...