Embedded JavaScript templates.
$ npm install ejs
- Complies with the Express view system
- Static caching of intermediate JavaScript
- Unbuffered code for conditionals etc
<% code %> - Escapes html by default with
<%= code %> - Unescaped buffering with
<%- code %> - Supports tag customization
<% if (user) { %>
<h2><%= user.name %></h2>
<% } %>
ejs.compile(str, options);
// => Function
ejs.render(str, options);
// => str
localsLocal variables objectcacheCompiled functions are cached, requiresfilenamefilenameUsed bycacheto key cachescontext|scopeFunction execution contextdebugOutput generated function bodyopenOpen tag, defaulting to "<%"closeClosing tag, defaulting to "%>"
Custom tags can also be applied globally:
var ejs = require('ejs');
ejs.open = '{{';
ejs.close = '}}';
Which would make the following a valid template:
<h1>{{= title }}</h1>