HTML Template Engine with JavaScript. (JS-Template)
Support most modern browsers, and NodeJS.
Latest stable version:v1.3.2
- fast, small and has no dependencies.
- support include inner template.
- support json, array and any js object as render data.
- concise syntax, easy to use.
- support all frequently-used browsers.
- support using html script or just string as template.
- support using under both browsers and nodejs.
uses script-tag to wrap template in html:
<script id="test" type="text/html">
<h1>{{title}}</h1>
<ul>
{{each list as value i}}
<li>Index. {{i + 1}} :{{value}}</li>
{{/each}}
</ul>
</script>
or just write the template content in a file:
<h1>{{title}}</h1>
<ul>
{{each list as value i}}
<li>Index. {{i + 1}} :{{value}}</li>
{{/each}}
</ul>
use zollty.render('test', data) to render template:
var data = {
title: 'This is title',
list: ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg']
};
var html = zollty.render('test', data);
document.getElementById('content').innerHTML = html;
npm install zollty-tmpl
var template = require('zollty-tmpl');
var data = {list: ["aaa", "test"]};
var html = template(__dirname + '/index/main', data);
Released under the MIT, BSD, and GPL Licenses zollty.com
See: JS模板引擎原理