@zollty/zollty-tmpl

1.3.2 • Public • Published

zollty-tmpl.js

HTML Template Engine with JavaScript. (JS-Template)

Support most modern browsers, and NodeJS.

Latest stable version:v1.3.2

Characteristic

  1. fast, small and has no dependencies.
  2. support include inner template.
  3. support json, array and any js object as render data.
  4. concise syntax, easy to use.
  5. support all frequently-used browsers.
  6. support using html script or just string as template.
  7. support using under both browsers and nodejs.

Usage

Writing templates

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>

Render template

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;

See Examples

Download

NodeJS

Install

npm install zollty-tmpl

Usage

var template = require('zollty-tmpl');
var data = {list: ["aaa", "test"]};

var html = template(__dirname + '/index/main', data);

Change-log

Licenses

Released under the MIT, BSD, and GPL Licenses zollty.com

See: JS模板引擎原理

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i @zollty/zollty-tmpl

    Weekly Downloads

    1

    Version

    1.3.2

    License

    MIT

    Unpacked Size

    112 kB

    Total Files

    11

    Last publish

    Collaborators

    • zollty