Fontend-tpl
This is a simple fontend template engine
Language
English || 中文
Usage
Browser
<script src="dist/tpl.js"></script>
<script>
var tpl = new Tpl()
var data = {
divClass: 'div',
out: 'outer'
}
var htmlString = ' \
<div class="{{ divClass }}"> \
<p>{{ "inner" }}</p> \
</div> \
<p>{{ out + "p" }}</p> \
'
var dom = tpl.parse(htmlString).render({ data: data }).getDom()
/**
* dom is:
* [
* <div class="div">
* <p>inner</p>
* </div>,
* <p>outerp</p>
* ]
*/
</script>
CommonJS
var Tpl = require('frontend-tpl')
var tpl = new Tpl()
Attention
If you want to use it in node environment, you should offer a environment of DOM.
For example, you can use the jsdom module.
Tests
You can download this depository and run npm test
to see the unit test.
Docs
If you want to get more information, please see API Document