koa-xtpl

A node.js wrapper around xtemplate engine (easier for Koa)

Usage no npm install needed!

<script type="module">
  import koaXtpl from 'https://cdn.skypack.dev/koa-xtpl';
</script>

README

koa-xtpl

NPM version NPM download Build Status Dependency Status devDependency Status Code Style

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

License

MIT © 汪磊