Skip to content

korbai/koa-cheerio-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Templating for koa using cheerio

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published