ejst
A embedded javascript template engine for nodejs.
- Auto cache template file to improving performance
- Include feature
Installation
$ npm install ejst --save
Usage
Render string template
const ejst = require('ejst')
let str = ejst.render('<h5><%=title%></h5>', { title: 'Hello' })
console.log(str)
Render file template
<div>
<div class="dialog">
<% if(typeof title === 'string'){ %>
<div class="dialog__hd">
<strong class="dialog__title"><%=title%></strong>
</div>
<% } %>
<div class="dialog__bd"><%=content%></div>
<div class="dialog__ft">
<% for(var i = 0; i < buttons.length; i++){ %>
<%=include('./examples/include.html', {button: buttons[i]})%>
<% } %>
</div>
</div>
</div>
<a href="javascript:;" class="dialog__btn dialog__btn_<%=button.type%>"><%=button.label%></a>
const ejst = require('ejst')
let data = {
title: 'Question',
content: 'Are you sure?',
buttons: [{ label: 'Yes', type: 'green' }, { label: 'No', type: 'gray' }]
}
let str = ejst.renderFile('./examples/index.html', data)
console.log(str)
Include
<div>
<% for(var i = 0; i < buttons.length; i++){ %>
<%=include('./examples/include.html', {button: buttons[i]})%>
<% } %>
</div>
License
MIT