Reusing templates with partials in EJS

Partial templates are larger sections of HTML which need to be included multiple times from multiple pages. Common uses for partial templates include headers, footers, site menus, login boxes, alerts, and so on.

The latest version of EJS doesn't natively support partial templates; they have been removed. However, there is another way to use other templates from within a template, by including the compiled template itself in the data model.

In this recipe, we're going to render a conversation thread using a recursive partial template written in EJS.

Getting ready

We need to download EJS from http://embeddedjs.com/ and extract ejs_production.js in our recipe folder.

How to do it...

Let's get started.

  1. Create index.html ...

Get HTML5 Data and Services Cookbook 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.