Skip to content
/ ejs Public
forked from tj/ejs

Embedded JavaScript templates for node - Express compliant

Notifications You must be signed in to change notification settings

ashleydev/ejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

About

Embedded JavaScript templates for node - Express compliant

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%