Templates with Embedded JavaScript

At the beginning of the chapter, we adopted the mechanism of templates called EJS, which is very easy to understand. Besides, EJS gives us the template logic functionality within its syntax and can be easily embedded within HTML files. Its use is very similar to that of Handlebars, another excellent JavaScript library to use templates; for example:

<h1><%= title %></h1>
<ul>
  <% for( var i = 0; i < bands.length; i++ ) { %>
    <li>
      <%= bands[i] %>
    </li>
  <% } %>
</ul>

It is very similar to other programming languages such as PHP and RoR.

However, you can use the template that suits you; Node.js has a great list of template engines for all tastes.

Tip

Another good option for a template engine is Swig, which can be installed ...

Get Learning Single-page Web Application Development 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.