Embedded JavaScript templates without the bells and whistles.
Why
sEJS spun out of an endeavor to understand how JavaScript templating (in the vein of ERB or PHP) works. It is:
-
A smaller EJS.
-
Similar to John Resig’s micro-templating script, but without regular expressions and with better error reporting.
Usage
var tmpl = '<% if (foo) { %>' + '<%= foo.bar %>, <%= foo.baz %>!' + '<% } %>';var data = foo: bar: 'Hello' baz: 'World' ; data; //=> 'Hello, World!'
Place JavaScript between <%
and %>
tags. To print a variable, use <%=
for the opening tag.
API
sejs(tmpl)(data)
Returns a String, the result of rendering tmpl
using values from data
.
tmpl
— The template String.data
— An Object literal of values.
Installation
Install via npm:
$ npm i --save sejs
Install via bower:
$ bower i --save yuanqing/sejs
To use sEJS in the browser, include the minified script in your HTML:
<!-- ... -->
Changelog
- 0.2.0
sejs(tmpl)(data)
replacessejs.render(tmpl, data)
- Remove
sejs.renderFile(tmplFile, data, cb)
- Add bower.json
- Add a minified version of the module
- 0.1.0
- Initial release