A Felid plugin for rendering Handlebars templates.
npm install felid-handlebars
or
yarn add felid-handlebars
const Felid = require('felid')
const handlebars = require('felid-handlebars')
const app = new Felid()
app.plugin(handlebars, options)
app.get('/', (req, res) => {
res.render('index.hbs', { foo: 'bar' })
})
- root: String: The directory where your template files locates. Default to the directory where node runs.
- charset: String: The charset your templates use. Default is:
utf-8
. - production: Boolean: If
true
, an LRU cache will be used to caching templates. Default is depend on the value ofprocess.env.NODE_ENV
. - initCache: Boolean: Whether to initialize the template caches when the plugin is being loaded. Default is:
false
. - cacheOptions: Object: The options passed to
lru-cache
. Wheremax
has a default value of100
. - decorator Object: Customize the decorator names. Default is:
{
render: 'render'
}
- onInit Function(engine HandlebarsInstance): If you need to customize the environment of Handlebars, just do it here! Read more about what you can do with Handlebars.
app.plugin(handlebars, {
onInit (hbs) {
// hbs.registerPartial(name, partial)
// hbs.registerHelper(name, helper)
}
})
- onProcess Function(html String) => String: A function used to process the HTML string before it is sent to the client.
app.plugin(handlebars, {
onProcess (html) {
// Do something with html here. For example: minify.
return html
}
})
- onError Function(error: Error, response: FelidResponse): A function invoked when an error occured in
res.render()
.
- response.render(template: String, context?: Object): Render the template using the context.