Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Embedded JavaScript templates for node
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
support
test
.gitmodules
History.md
Makefile
Readme.md
benchmark.js
index.js
package.json

Readme.md

EJS

Embedded JavaScript templates.

Installation

$ npm install ejs

Features

  • 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

Example

<% if (user) { %>
  <h2><%= user.name %></h2>
<% } %>

Usage

ejs.compile(str, options);
// => Function

ejs.render(str, options);
// => str

Options

  • locals Local variables object
  • cache Compiled functions are cached, requires filename
  • filename Used by cache to key caches
  • context|scope Function execution context
  • debug Output generated function body
  • open Open tag, defaulting to "<%"
  • close Closing tag, defaulting to "%>"

Custom Tags

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>
Something went wrong with that request. Please try again.