0.0.2 • Published 7 months ago
khbs v0.0.2
khbs
A KoaJS middleware library for using handlebars templates
Installation
npm install khbs
Usage
The layout ./layouts/main.hbs
<html>
<head>
<title>Testy Test</title>
<head>
<body>
{{{embed}}}
</body>
</html>
The View ./views/home.hbs
{{> 'header' msg=msg}}
<h1>{{msg}}</h1>
The partial ./partials/header.hbs
<h1>MSG: {{msg}}</h1>
The app ./server.js
const Koa = require('koa');
const Router = require('@koa/router');
const { middleware } = require('khbs');
const app = new Koa();
const router = new Router();
const khbs = middleware({
ext: '.hbs', // extension of your handlebars templates
views: 'views', // path to the views directory
layouts: 'layouts', // path to the layouts directory
partials: 'partials', // path to the partials directory
});
router.get("/", async ctx => {
ctx.render('home', { msg: 'Hello World' }, 'main');
});
app.use(khbs);
app.use(router.routes());
app.listen(3000, () => {
console.log('listening on port 3000');
});
Contributing
- Fork it ( https://github.com/[my-github-username]/khbs/fork )
- Create your feature branch (git checkout -b feature/my_new_feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request