# opentpl

> OTPL for Nodejs

Latest version **0.4.1** (published 2016-08-09) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install opentpl
pnpm add opentpl
yarn add opentpl
bun add opentpl
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2016-08-09 |
| First published | 2016-08-09 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jun Hwong |
| Maintainers | opentpl |
| Keywords | otpl, otpl-node, opentpl, template, node, template, javascript, render |

## Links

- npm: https://www.npmjs.com/package/opentpl
- Repository: https://github.com/opentpl/otpl-node
- Homepage: https://github.com/opentpl/otpl-node#readme
- Issues: https://github.com/opentpl/otpl-node/issues
- npm.io page: https://npm.io/package/opentpl

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2016-08-09

## README

# otpl-node

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url]

OTPL for Nodejs (Typescript). 



## OTPL规范/文档

[OTPL Spec](https://github.com/diosay/open-tpl).

[Developer Doc](https://github.com/diosay/otpl-node/blob/master/src/README.md).

## 安装

```bash
$ npm install --save otpl
```

## 用例
```js
const otpl = require('opentpl')

otpl.config(__dirname,{
    debug:true,
    ...
})

//使用 koa 框架为例
const app = require('koa')();

//注册中间件
app.use(function *(next){
	this.otpl = function* (view, data) {
        let ctx = this
        yield new Promise((resolve, reject) => {
            let callback = function (err, rendered) {
                if (err) {
                    rendered = err.message;
                    console.log('render error:', err)
                }
				this.type = 'text/html;charset=UTF-8'
                ctx.body = rendered
                resolve(rendered)
            }
            otpl.render(view, data, callback)
        })
    }
	yield next;
});

app.use(function *(next){
    this.otpl('index',{foo:'bar'}) // /views/index.otpl.html
})

app.listen(3000,function(err){
	console.log('serve on port: 3000');
});

```


[downloads-image]: https://img.shields.io/npm/dm/otpl.svg

[npm-url]: https://www.npmjs.com/package/otpl
[npm-image]: https://img.shields.io/npm/v/otpl.svg

[travis-url]: https://travis-ci.org/diosay/otpl-node
[travis-image]: https://img.shields.io/travis/diosay/otpl-node.svg

[coveralls-url]: https://coveralls.io/r/diosay/otpl-node
[coveralls-image]: https://img.shields.io/coveralls/diosay/otpl-node/master.svg

[gitter-url]: https://gitter.im/diosay/otpl-node
[gitter-image]: https://badges.gitter.im/diosay/otpl-node.png

---
_Source: https://npm.io/package/opentpl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
