0.1.1 • Published 10 years ago
silly-ejs v0.1.1
silly-ejs
A simple and small implement for EJS
Install
npm
npm i silly-ejs --savebower
bower install silly-ejsUsage
var ejs = require('silly-ejs');
var tpl = '<div><%= name %><% if (age > 17) { %>(adult)<% } %> <%- html %></div>';
var data = {
name: 'Hans Chan',
age: 18,
html: '<p>test</p>'
};
var html = ejs(tpl, data);
console.log(html);
// '<div>Hans Chan(adult) <p>test</p></div>'Features
- Control flow with
<% %> - Escaped output with
<%= %> - Unescaped raw output with
<%- %> - Custom delimiters (e.g., use
<$ $>instead of<% %>)
Custom delimiters
Custom delimiters can be applied on a per-template basis, or globally:
var ejs = require('silly-ejs');
//Custom delimiters
ejs.delimiters = '$';
var tpl = '<div><$= name $><$ if (age > 17) { %>(adult)<% } $></div>';
var data = {
name: 'Hans Chan',
age: 18
};
var html = ejs(tpl, data);
console.log(html);
// '<div>Hans Chan(adult)</div>'