1.2.4 • Published 8 years ago

koa-cheerio-template v1.2.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

koa-cheerio-template

Templating for koa using cheerio. Inspired by cheerio-template which I used a lot for my express based projects.

Features

  • "no template" style server side templating with jQuery syntax
  • optional isomorphic support (see example)
  • layout, extend, placeholder, block, include
  • unlimited level of hierarchy
  • html editor friendly

Installation

npm install koa-cheerio-template

Example

views/index.html

<div data-template-extend="main"></div>

<div data-template-block="head">
    <title>Templating Demo</title>
</div>

<div data-template-block="content">
    <h2>Sample for including component</h2>
    <div data-template-include="component"></div>
    Hello <span id="hello"></span>
</div>

<script data-template-block="code">
    var z = 345;
</script>

See the full example!

var path = require('path');
var app = require('koa')();
var render = require('koa-cheerio-template');

app.use(render({
  root: path.join(__dirname, 'views/'),
  ext: '.html'
}));

app.use(function * (next) {
  var $ = yield this.render('index');
  $('#hello').text(', World!');
});

app.listen(3000);

see cheerio-readme and htmlparser2 for more information

# License

  MIT
1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

9 years ago

1.1.0

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago