0.0.2 • Published 7 months ago

khbs v0.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

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

  1. Fork it ( https://github.com/[my-github-username]/khbs/fork )
  2. Create your feature branch (git checkout -b feature/my_new_feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
0.0.2

7 months ago

0.0.1

7 months ago