Using HTML Templates
In this chapter, I describe how templates are used to generate HTML content, allowing an application to adapt the content display to the user to reflect the request that is being processed or the application’s state data.
Like many of the topics described in this book, templates are much easier to understand once you see how they work. Therefore, I will start by creating a simple custom template system using just the features provided by the JavaScript and Node.js APIs, just to explain how the pieces fit together. I will demonstrate server-side templates, where the backend server generates the HTML content, and client-side templates, where the browser generates the content.
The custom templates in this chapter are educational but too limited for use in a real project, so I also introduce a popular template package that has many more features and much better performance, and which is suitable for use in a real project. Table 10.1 puts HTML templates...