Chapter 7. Templating with Handlebars
In this chapter, we’ll cover templating, which is a technique for constructing and formating your content to display to the user. You can think of templating as an evolution of the form letter: “Dear [Name]: we regret to inform you nobody uses [Outdated Technology] anymore, but templating is alive and well!” To send that letter to a bunch of people, you just have to replace [Name] and [Outdated Technology].
Note
This process of replacing fields is sometimes called interpolation, which is just a fancy word for “supplying missing information” in this context.
While server-side templating is being fast supplanted by frontend frameworks like React, Angular, and Vue, it still has applications, like creating HTML email. Also, Angular and Vue both use a template-like approach to writing HTML, so what you learn about server-side templating will transfer to those frontend frameworks.
If you’re coming from a PHP background, you may wonder what the fuss is all about: PHP is one of the first languages that could really be called a templating language. Almost all major languages that have been adapted for the web have included some kind of templating support. What is different today is that the templating engine is being decoupled from the language.
So what does templating look like? Let’s start with what templating is replacing by considering the most obvious and straightforward way to generate one language from another (specifically, we’ll generate ...
Get Web Development with Node and Express, 2nd Edition 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.