vision

Template rendering support for hapi.js.

Latest Version: 6.0.0
hapi-family
Installation:

npm: npm install @hapi/vision

yarn: yarn add @hapi/vision

Module Status:
Version License Node Dependencies Travis End of Life
6.0.0
hapi helmet github logo
BSD 12 Dependency Status Build Status

Introduction

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.

Most interaction with vision is done via the h response toolkit
and server interfaces.

Example

const Hapi = require('@hapi/hapi');
const Vision = require('@hapi/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();

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

☝️ 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
- twig

vision 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.