package
Templates rendering plugin support for hapi.js
npm install visionGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Templates rendering plugin support for hapi.js.
Lead Maintainer - William Woodruff
vision decorates the server,
request, and
h response toolkit interfaces with additional
methods for managing view engines that can be used to render templated responses.
vision also provides a built-in handler implementation for creating templated responses.
See also the API Reference
const Hapi = require('hapi');
const Vision = require('vision');
const server = Hapi.Server({ port: 3000 });
const provision = async () => {
await server.register(Vision);
await server.start();
console.log('Server running at:', server.info.uri);
};
provision();5.x.x requires hapi 17.x.x. For use with hapi 16.x.x, use vision 4.x.x.9.0.The examples in the examples folder can be run with node.
git clone https://github.com/hapijs/vision.git && cd vision
npm install
node examples/handlebars:point_up: That command will run the handlebars basic template. There are three more examples in there: for helpers, layout, and partials.
Use this hierarchy to know which commands to run, e.g.
node examples/mustache
node examples/mustache/partials
node examples/jsx- cms // A bare-bones Content Management System with a WYSIWYG editor
- ejs
- layout
- handlebars
- helpers
- layout
- partials
- jsx // React server-side rendering with `hapi-react-views`
- marko
- mixed // Using multiple render engines (handlebars and pug)
- mustache
- layout
- partials
- nunjucks
- pug
- twigvision is compatible with most major templating engines out of the box. Engines that don't follow
the normal API pattern can still be used by mapping their API to the vision API. Some of the examples below use the compile and prepare methods which are part of the API.
const Hapi = require('hapi');
const Vision = require('vision');
const Ejs = require('ejs');
const server = Hapi.Server({ port: 3000 });
const rootHandler = (request, h) => {
return h.view('index', {
title: 'examples/ejs/templates/basic | Hapi ' + request.server.version,
message: 'Hello Ejs!'
});
};
const provision = async () => {
const Hapi = require('hapi');
const Vision = require('vision');
const Handlebars = require('handlebars');
const server = Hapi.Server({ port: 3000 });
const rootHandler = (request, h) => {
return h.view('index', {
title: 'examples/handlebars/templates/basic | Hapi ' + request.server.version,
message: 'Hello Handlebars!'
});
};
const provision = async () =>
const Hapi = require('hapi');
const Vision = require('vision');
const Pug = require('pug');
const Path = require('path');
const server = Hapi.Server({ port: 3000 });
const rootHandler = (request, h) => {
return h.view('index', {
title: 'examples/pug/templates | Hapi ' + request.server.version,
message: 'Hello Pug!'
});
};
const Hapi = require('hapi');
const Vision = require('vision');
const Marko = require('marko');
const server = Hapi.Server({ port: 3000 });
const rootHandler = (request, h) => {
return h.view('index', {
title: 'examples/marko/templates | Hapi ' + request.server.version,
message: 'Hello Marko!'
});
};
const provision = async () => {
const Hapi = require('hapi');
const Vision = require('vision');
const Mustache = require('mustache');
const server = Hapi.Server({ port: 3000 });
const rootHandler = (request, h) => {
return h.view('index', {
title: 'examples/mustache/templates/basic | Hapi ' + request.server.version,
message: 'Hello Mustache!'
});
};
const provision = async () => {
const Hapi = require('hapi');
const Vision = require('vision');
const Nunjucks = require('nunjucks');
const server = Hapi.Server({ port: 3000 });
const rootHandler = (request, h) => {
return h.view('index', {
title: 'examples/nunjucks/templates | Hapi ' + request.server.version,
message: 'Hello Nunjucks!'
});
};
const provision = async () => {
const Hapi = require('hapi');
const Vision = require('vision');
const Twig = require('twig');
const server = Hapi.Server({ port: 3000 });
const rootHandler = (request, h) => {
return h.view('index', {
title: 'examples/twig/templates | Hapi ' + request.server.version,
message: 'Hello Twig!'
});
};
const provision = async () => {
devinivy
devinivy@gmail.com