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
locals
Local variables objectcache
Compiled functions are cached, requiresfilename
filename
Used bycache
to key cachescontext|scope
Function execution contextdebug
Output generated function bodyopen
Open tag, defaulting to "<%"close
Closing 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>