# koa-render

> Add a `render()` method to koa that allows you to render almost any templating engine

Latest version **0.2.1** (published 2014-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-render
pnpm add koa-render
yarn add koa-render
bun add koa-render
```

## Health

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

Positive: no vulnerabilities.

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

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2014-01-02 |
| First published | 2013-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 706 |
| Author | queckezz |
| Maintainers | queckezz |
| Keywords | koa, render, views, app-wide |

## Links

- npm: https://www.npmjs.com/package/koa-render
- Repository: https://github.com/queckezz/koa-render
- Issues: https://github.com/queckezz/koa-render/issues
- npm.io page: https://npm.io/package/koa-render

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ~0.7.4
- [merge](https://npm.io/package/merge.md) git://github.com/yields/merge
- [co-views](https://npm.io/package/co-views.md) *

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2014-01-02
- 0.2.0 — 2014-01-01
- 0.1.2 — 2013-12-30
- 0.1.1 — 2013-12-22
- 0.1.0 — 2013-12-21
- 0.0.1 — 2013-12-19

## README

## koa-render
 
Add a `render()` method to koa that allows you to render almost any templating engine.
 
Extending koa by adding a `render()` method has the advantage that you can define your views settings once and have them available throughout your app, even when you `mount()` another app with koa-mount.
 
## Installation
 
    $ npm i --save koa-render
 
## Usage
 
### views(path, [ext, map])
 
* `ext`: define the default extension name. Defaults to `html`
* `map`: custom mapping.
 
Use `views` in a koa middleware with given options and yield it to `this.body`.

If you use an engine that has the same extension as the engine itself you can use a shorthand

```javascript
	app.use(views('./example', 'jade'));
    
    // in your route handler
    this.body = yield this.render('index');
```

otherwise you can `map` an extension to an engine. In this case we map all files with the extension `.html` to underscore.

```javascript
app.use(views('./example', {
  html: 'underscore'
}));

// in your route handler
this.body = yield this.render('index');
```

You can use different engines throughout your app just by mapping different extension names to engines.

```javascript
app.use(views('./example', 'jade', {
  html: 'underscore',
  jade: 'jade'
}));

// route: A (renders index.jade)
this.body = yield this.render('index');

// route: B (renders index.html with underscore)
this.body = yield this.render('index.html');
```

__Note__: Make sure that you define `views()` before you mount other koa apps.
 
For full examples take a look at the examples folder.
 
## Licence
 
MIT

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