xtemplate
Version:
eXtensible Template Engine lib on browser and nodejs. support async control, inheritance, include, logic expression, custom function and more.
53 lines (48 loc) • 1.13 kB
JavaScript
var xtpl = require('xtpl');
xtpl.config({
XTemplate: require('../')
});
var app = require('express')();
var path = require('path');
function getData() {
return {
cache: true,
settings: {
views: __dirname + '/views/includes'
},
title: 'Demo',
views: path.join(__dirname, 'views'),
using: true,
lis: [
{
d: 'one'
},
{
d: 'two'
},
{
d: 'three'
}
]
};
}
xtpl.renderFile(path.resolve(__dirname,'./views/includes/main.xtpl'), getData(), function (err, content) {
console.log(err || content);
});
function fn(count, callback) {
if (count <= 0) {
callback();
return;
}
xtpl.renderFile('./views/includes/main.xtpl', getData(), function () {
});
setTimeout(function () {
fn(--count, callback);
}, 0);
}
app.get('/', function (req, res) {
fn(100000000, function () {
res.send('ok');
})
});
app.listen(9000);