koa-views-handlebars
Handlebars template engine middleware for koa@2
based on koa-views
.
Installation
npm install koa-views-handlebars --save
Templating engines
koa-views-handlebars
is using koa-views under the hood, but provide easy way to config helpers and partails of handlebars.
NOTE: you must install the koa-views
and handlebars
before use this middleware, add them to your package.json dependencies.
npm install koa-views handlebars --save
Example
const hbs = ; // setup middleware before routerapp; app;
For more examples you can take a look at the tests.
API
hbs(rootPath, options)
rootPath
: Where your views are located. Must be an absolute path. All rendered views are relative to this pathoptions
(optional)
Very simple example.
app
options.extension
: handelbars template file extension, default ishbs
.
In this example, each file ending with .html
will get rendered using the handlebars
templating engine.
app
options.helperDirs
: where your handlebars helpers are located, can be string (one dir) or array (multiple dirs).
// helpers in one dirapp; // helpers in multiple dirsapp;
options.partialDirs
: where your handlebars partials are located, can be string (one dir) or array (multiple dirs).
// partials in one dirapp; // partials in multiple dirs (related path)app;
options.debug
: set to true will print final options passed to koa-views
app;