nodejs wrapper around xtemplate engine
npm install xtplnodejs wrapper around xtemplate engine (easier for expressjs and koajs)





refer: https://github.com/xtemplate/xtemplate
#### methods
##### config or get xtpl global option:
``javascript`
Object config(option:Object)
option details:
| name | type | default | description |
|---|---|---|---|
| encoding | String | utf-8 | xtpl file encoding |
| XTemplate | Object | require('xtemplate') | xtemplate module value |
if options is undefined, then this method will return global config.
##### render file
`javascript`
void renderFile(path:String, options:Object, callback:function)
parameter details:
name
type
default
description
path
String
xtpl template file
option
Object
data to be rendered. the following properties will be used for control.
name
type
default
description
cache
Boolean
false
whether cache xtpl by path
setting['view encoding']
String
global encoding
encoding for read xtpl files
callback
function
callback
``
npm install xtpl xtemplate --save
`javascript
var xtpl = require('xtpl');
xtpl.renderFile('./x.xtpl',{
x:1
},function(error,content){
});
`
##### express adaptor
`javascript`
xtpl.__express = xtpl.renderFile
##### clear cache
clear xtemplate cache cached by xtpl file path
`javascript`
void clearCache(path:String);
`javascript`
var app = require('express')();
app.set('views','./views');
app.set('view engine', 'xtpl');
app.use(function(req, res){
res.render('test',{data:1});
});
`javascript``
var app = require('xtpl/lib/koa2')(new require('koa')(),{
views:'./views'
});
app.use(async function(ctx){
await ctx.render('test',{data:1});
});
├── footer.xtpl
├── header.xtpl
├── index.xtpl
├── layout.xtpl
├── layout1.xtpl
└── sub
└── header.xtpl
index.xtpl
{{extend ("./layout1")}}
{{#block ("head")}}
{{/block}}
{{#block ("body")}}
layout1.xtpl
render
res.render("index", {title: "xtpl engine!"})
output
https://github.com/xtemplate/xtpl/milestones
xtpl is released under the MIT license.