tem

template4js

The JavaScript template engine, support for running NodeJS and browser environment.

Showing:

Popularity

Downloads/wk

22

GitHub Stars

2

Maintenance

Last Commit

7yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

1.2KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

#template4js#

The JavaScript template engine, support for running NodeJS and browser environment.

##installation##

npm install template4js

##usage##

<ul>
<% for (var i = 0, l = list.length; i < l; i ++) { %>
    <li><%=list[i].index%>user: <%=list[i].user%> | site:<%=list[i].site%></li>
<% } %>
</ul>

var template = require('template4js'),
    http = require('http');

var data = {list : [{
        index : 1,
        user : 'baidu',
        site : '<a href="http://www.baidu.com" target="_blank">http://www.baidu.com</a>'
    },{
        index : 2,
        user : 'qq',
        site : 'http://www.qq.com'
    },{
        index : 3,
        user : 'ali',
        site : "http://www.taobao.com"
    }
]};

var server = http.createServer(function(req, res){
    var contentType = 'text/html;charset=utf-8';
    res.setHeader("Content-Type", contentType);
    res.end(template('./assets/demo.tpl', data));
}).listen(80);

  • <%=var%> : output variable
  • <%-var%> : output escaping after the variables
  • <% include('./static/template/header.tpl') %> : Nested template

In the template, the variable, please are reflected in the data parameters. Please read demo.html or node_demo.js.

##License##

Released under the MIT license

hechangmin@gmail.com

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100