xtpl
a template engine based on kissy xtemplate
Last updated 11 years ago by yiminghe .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install xtpl 
SYNC missed versions from official npm registry.

xtpl

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

xtpl NPM downloads Build Status Coverage Status Dependency Status

docs

syntax

refer: https://github.com/xtemplate/xtemplate

api

methods

config or get xtpl global option:
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
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
var xtpl = require('xtpl');
xtpl.renderFile('./x.xtpl',{
	x:1
},function(error,content){

});
express adaptor
xtpl.__express = xtpl.renderFile
clear cache

clear xtemplate cache cached by xtpl file path

void clearCache(path:String);

use for expressjs

var app = require('express')();
app.set('views','./views');
app.set('view engine', 'xtpl');
app.use(function(req, res){
    res.render('test',{data:1});
});

use for koa

var app = require('xtpl/lib/koa2')(new require('koa')(),{
    views:'./views'
});
app.use(async function(ctx){
    await ctx.render('test',{data:1});
});

Example

├── footer.xtpl
├── header.xtpl
├── index.xtpl
├── layout.xtpl
├── layout1.xtpl
└── sub
    └── header.xtpl

index.xtpl

{{extend ("./layout1")}}

{{#block ("head")}}
<!--index head block-->
<link type="text/css" href="test.css" rev="stylesheet" rel="stylesheet"  />
{{/block}}

{{#block ("body")}}
<!--index body block-->
<h2>{{title}}</h2>
{{/block}}

layout1.xtpl

<!doctype html>
<html>
<head>
<meta name="charset" content="utf-8" />
<title>{{title}}</title>
{{{block ("head")}}}
</head>
<body>
{{{include ("./header")}}}
{{{block ("body")}}}
{{{include ("./footer")}}}
</body>
</html>

render

res.render("index", {title: "xtpl engine!"})

output

<!doctype html>
<html>
<head>
<meta name="charset" content="utf-8" />
<title>xtpl engine!</title>

<!--index head block-->
<link type="text/css" href="test.css" rev="stylesheet" rel="stylesheet"  />

</head>
<body>
<h1>header</h1>
<h2>sub header</h2>

<!--index body block-->
<h2>xtpl engine!</h2>

<h1>footer</h1>

</body>
</html>

changelog

https://github.com/xtemplate/xtpl/milestones

License

xtpl is released under the MIT license.

Current Tags

  • 3.4.2                                ...           latest (5 years ago)

60 Versions

  • 3.4.2                                ...           5 years ago
  • 3.4.1                                ...           5 years ago
  • 3.4.0                                ...           7 years ago
  • 3.3.0                                ...           8 years ago
  • 3.2.0                                ...           10 years ago
  • 3.1.9                                ...           10 years ago
  • 3.1.8                                ...           10 years ago
  • 3.1.7                                ...           10 years ago
  • 3.1.6                                ...           10 years ago
  • 3.1.5                                ...           10 years ago
  • 3.1.4                                ...           10 years ago
  • 3.1.3                                ...           10 years ago
  • 3.1.2                                ...           10 years ago
  • 3.1.1                                ...           10 years ago
  • 3.1.0                                ...           10 years ago
  • 3.0.0                                ...           10 years ago
  • 2.1.0                                ...           10 years ago
  • 2.0.3                                ...           10 years ago
  • 2.0.2                                ...           10 years ago
  • 2.0.1                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.1.3                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.17.2                                ...           10 years ago
  • 0.17.1                                ...           10 years ago
  • 0.17.0                                ...           10 years ago
  • 0.16.0                                ...           10 years ago
  • 0.15.2                                ...           11 years ago
  • 0.15.0                                ...           11 years ago
  • 0.14.0                                ...           11 years ago
  • 0.13.0                                ...           11 years ago
  • 0.12.1                                ...           11 years ago
  • 0.12.0                                ...           11 years ago
  • 0.11.0                                ...           11 years ago
  • 0.10.0                                ...           11 years ago
  • 0.9.5                                ...           11 years ago
  • 0.9.4                                ...           11 years ago
  • 0.9.3                                ...           11 years ago
  • 0.9.2                                ...           11 years ago
  • 0.9.1                                ...           11 years ago
  • 0.9.0                                ...           11 years ago
  • 0.8.0                                ...           11 years ago
  • 0.7.3                                ...           11 years ago
  • 0.7.2                                ...           11 years ago
  • 0.7.0                                ...           11 years ago
  • 0.6.0                                ...           11 years ago
  • 0.5.0                                ...           11 years ago
  • 0.4.1                                ...           11 years ago
  • 0.3.4                                ...           11 years ago
  • 0.3.3                                ...           11 years ago
  • 0.3.2                                ...           11 years ago
  • 0.3.1                                ...           11 years ago
  • 0.3.0                                ...           11 years ago
  • 0.2.1                                ...           11 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (2)
Downloads
Total 1
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE