2.4.0 • Published 10 years ago

template4js v2.4.0

Weekly downloads
90
License
-
Repository
github
Last release
10 years ago

#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

2.4.0

10 years ago

2.3.8

10 years ago

2.3.7

10 years ago

2.3.6

10 years ago

2.3.5

10 years ago

2.3.4

10 years ago

2.3.2

10 years ago

2.3.1

10 years ago

2.3.0

10 years ago

2.2.9

10 years ago

2.2.8

11 years ago

2.2.7

11 years ago

2.2.6

11 years ago

2.2.5

11 years ago

2.2.4

11 years ago

2.2.3

11 years ago

2.2.2

11 years ago

2.2.1

11 years ago

2.2.0

11 years ago

2.1.0

11 years ago

2.0.1

11 years ago

2.0.0

11 years ago