koa-xtpl
v2.1.1
Published
A node.js wrapper around xtemplate engine (easier for Koa)
Downloads
33
Readme
koa-xtpl
A node.js wrapper around xtemplate engine (easier for Koa 2)
Install
# npm
$ npm install koa-xtpl --save
# or yarn
$ yarn add koa-xtpl
Usage
demo.xtpl
<p>{{ title }}</p>
demo.js
const path = require('path')
const Koa = require('koa')
const xtpl = require('koa-xtpl')
const app = new Koa()
// root
app.use(xtpl(path.join(__dirname, 'views')))
// or options
app.use(xtpl({
root: path.join(__dirname, 'views'),
extname: 'xtpl',
commands: {}
}))
app.use(async ctx => {
await ctx.render('demo', { title: new Date() })
})
app.listen(3000)
API
xtpl(options)
options
Type: object
or string
Option or view root directory
root
Type: string
commands
Type: object
extname
Type: string
catchError
Type: boolean
encoding
Type: string
Default: utf-8
strict
Type: boolean
cache
Type: boolean