围绕 xtemplate 引擎的 nodejs 包 (对于 expressjs 和 koajs 更方便)
nodejs wrapper around xtemplate engine (easier for expressjs and koajs)
refer: https://github.com/xtemplate/xtemplate
Object config(option:Object)option details:
name
type
default
description
encoding
String
utf-8
xtpl file encoding
XTemplate
Object
require('xtemplate')
xtemplate module valueif options is undefined, then this method will return global config.
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
callbacknpm install xtpl xtemplate --savevar xtpl = require('xtpl');
xtpl.renderFile('./x.xtpl',{
x:1
},function(error,content){
});xtpl.__express = xtpl.renderFileclear xtemplate cache cached by xtpl file path
void clearCache(path:String);var app = require('express')();
app.set('views','./views');
app.set('view engine', 'xtpl');
app.use(function(req, res){
res.render('test',{data:1});
});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.xtplindex.xtpl
{{extend ("./layout1")}}
{{#block ("head")}}
{{/block}}
{{#block ("body")}}{{title}}
{{/block}}layout1.xtpl
{{title}}
{{{block ("head")}}}
{{{include ("./header")}}}
{{{block ("body")}}}
{{{include ("./footer")}}}render
res.render("index", {title: "xtpl engine!"})output
xtpl engine!header
sub header
xtpl engine!
footer
https://github.com/xtemplate/xtpl/milestones
xtpl is released under the MIT license.
暂无开放 Issues,或尚未同步最近议题。