Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zce/koa-xtpl
A node.js wrapper around xtemplate engine (easier for Koa 2)
https://github.com/zce/koa-xtpl
Last synced: 2 months ago
JSON representation
A node.js wrapper around xtemplate engine (easier for Koa 2)
- Host: GitHub
- URL: https://github.com/zce/koa-xtpl
- Owner: zce
- License: mit
- Created: 2016-12-20T13:16:06.000Z (almost 8 years ago)
- Default Branch: v2.x
- Last Pushed: 2023-04-17T14:06:26.000Z (over 1 year ago)
- Last Synced: 2024-10-01T14:58:01.080Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - koa-xtpl - xtemplate模板引擎的封装(使其在Koa 2使用更简单). ![](https://img.shields.io/github/stars/zce/koa-xtpl.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-xtpl.svg?style=flat-square) (仓库 / 中间件)
README
# koa-xtpl
[![NPM version][npm-image]][npm-url]
[![NPM download][download-image]][download-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][dependency-image]][dependency-url]
[![devDependency Status][devdependency-image]][devdependency-url]
[![Code Style][style-image]][style-url][npm-image]: https://badge.fury.io/js/koa-xtpl.svg
[npm-url]: https://npmjs.org/package/koa-xtpl
[download-image]: https://img.shields.io/npm/dm/koa-xtpl.svg
[download-url]: https://npmjs.org/package/koa-xtpl
[travis-image]: https://travis-ci.org/zce/koa-xtpl.svg?branch=v2.x
[travis-url]: https://travis-ci.org/zce/koa-xtpl
[dependency-image]: https://david-dm.org/zce/koa-xtpl/status.svg
[dependency-url]: https://david-dm.org/zce/koa-xtpl
[devdependency-image]: https://david-dm.org/zce/koa-xtpl/dev-status.svg
[devdependency-url]: https://david-dm.org/zce/koa-xtpl?type=dev
[style-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
[style-url]: http://standardjs.com/> A node.js wrapper around xtemplate engine (easier for Koa 2)
## Install
```sh
# npm
$ npm install koa-xtpl --save
# or yarn
$ yarn add koa-xtpl
```## Usage
demo.xtpl
```html{{ title }}
```demo.js
```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](LICENSE) © [汪磊](http://github.com/zce)