Book Image

Web Development with MongoDB and Node.js

By : Jason Krol
Book Image

Web Development with MongoDB and Node.js

By: Jason Krol

Overview of this book

This book is designed for developers of any skill level that want to get up and running using Node.js and MongoDB to build full featured web applications. A basic understanding of JavaScript and HTML is the only requirement for this book.
Table of Contents (14 chapters)
12
12. Popular Node.js Web Frameworks
13
Index

Partial views


So far we've created a View, which acts as the bulk of the HTML for a specific page, and a layout, which acts as the wrapper for the consistent parts of the website on every page. Next up, let's take a look at creating partials, which are really just small views that we can reuse and inject inside our layouts or views.

Partials are a terrific way to create reusable components in your website and reduce code duplication. Consider the comments in our application. We have an HTML form defined that a user uses to submit a comment, but what if we wanted to allow users to post comments from a number of different areas throughout the website. This type of scenario is a great candidate for moving our comment form out to its own partial and then just including that partial anywhere we want to display the comment form.

For this app, we're using partials specifically for the sidebar in the main layout. With every view's ViewModel, we will include a JavaScript object called sidebar that...