koa-cheerio-template
Koa view render based on Cheerio for html templating with isomorphic support
Last updated 2 years ago by korbai .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install koa-cheerio-template 
SYNC missed versions from official npm registry.

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
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |