2.2.0 • Published 5 years ago
toisu-handlebars v2.2.0
toisu-handlebars
toisu-handlebars is a handlebars wrapper for the TOISU! server micro-framework.
install
To install toisu-handlebars into your project, use:
npm install --save toisu-handlebars
usage
const http = require('http');
const Toisu = require('toisu');
const toisuHandlebars = require('toisu-handlebars');
const dbModule = require('./a-bd-module');
const template = `
<!doctype html>
<html>
<head><title>Hello, world!</title></head>
<body>{{bodyContent}}</body>
</html>
`;
const app = new Toisu();
// Put some template data on the context.
app.use(async function () {
const bodyContent = await dbModule.get();
this.set('templateData', {bodyContent});
});
// toisu handlebars compiles the template and returns a middleware function.
app.use(toisuHandlebars(template));
http.createServer(app.requestHandler).listen(3000);