Templating and Views - Introduction

In the early days of the web websites consisted of relatively few pages so managing the content was a relatively straightforward task. As websites grew to dozens and even hundreds of pages this task became more challenging.

If a navbar which appeared on every page in the site needed to be updated this could mean having to update hundreds of pages which contained the navbar.

Server Side Includes and Frames were some of the approaches used in the early days to allow navigation bars (and other content which appeared on every page) to be stored in separate files and included or pulled-in to the other pages on the site. 

This allowed authors to update the content in one place and have those changes propogate through wherever that content was repeated.

This basic idea is crystalised in the DRY principle. "Don't Repeat Yourself". Wherever content is the same it should be referenced and pulled-in rather than copied. As a programmer or web-author once you get into duplication of code or content you start to create a tangled mess where it becomes hard to keep track of where everything is duplicated and errors are commonplace.

As a website grows to dozens or even hundreds of webpages it may be necessary to assign the resposibility for the management of different sections of the site to different individuals.

A typical website will have an overall navbar and possibly different sub-navbars for different sections of the site. In order to avoid having to change hundreds of pages if there is a slight change in the navbar we need to have I single location where aspects of the website which are to appear on all pages is managed.

Using this approach any changes to the navbar this need only be made in that one file and all the other pages will effectively "inherit" these changes.

Modern MVC frameworks use a View inheritance model to achieve this re-use and easy management of the site content. The basic standard inheritance model has three levels of inheritance.

Leave a Reply