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.
Create
index.html
, which will contain the conversation placeholder, the main conversation template, and the recursive partial thread template:<!DOCTYPE HTML> <html> <head> <title>Partials in EJS</title> <link rel="stylesheet" type...