O'Reilly logo

Mastering JavaScript Single Page Application Development by John Moore, Philip Klauzinski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Embedded JavaScript (EJS)

EJS is a JavaScript templating engine that works much like Underscore.js and also uses ERB <% %> style delimiters. Alternatively, it also allows the use of [% %] style tags for delimiters.

Just like Underscore.js, EJS allows arbitrary JavaScript to be parsed when used with the standard <% %> ERB style syntax, and allows the evaluation of expressions using an equals sign = following the opening delimiter tag <%= %>:

<ul> 
<% for (var i = 0; i < people.length; i++) { %> 
    <li><%= firstName %> <%= lastName %></li> 
<% } %> 
</ul> 

This template can be used to iterate over a list of objects from which key names are evaluated as variables with different values:

{ "people": [ { "firstName": "Peebo", "lastName": "Sanderson" }, { "firstName": ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required