# bogart-handlebars

> Handlebars tools for Bogart

Latest version **0.10.7** (published 2016-10-19) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install bogart-handlebars
pnpm add bogart-handlebars
yarn add bogart-handlebars
bun add bogart-handlebars
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.7 |
| Published | 2016-10-19 |
| First published | 2012-01-14 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Nathan Stott |
| Maintainers | jdc0589, nathan, soitgoes |
| Keywords | handlebars, bogart, respond |

## Links

- npm: https://www.npmjs.com/package/bogart-handlebars
- npm.io page: https://npm.io/package/bogart-handlebars

## Dependencies (4)

- [handlebars](https://npm.io/package/handlebars.md) ^4.0.5
- [underscore](https://npm.io/package/underscore.md) ~1.6.0
- [handlebars-layouts](https://npm.io/package/handlebars-layouts.md) =3.1.3
- [handlebars-load-tree](https://npm.io/package/handlebars-load-tree.md) =0.10.3

## Recent versions

- 0.10.7 (latest) — 2016-10-19
- 0.10.6 — 2016-10-19
- 0.10.5 — 2016-10-13
- 0.10.4 — 2016-10-07
- 0.10.3 — 2016-10-07
- 0.10.2 — 2016-10-06
- 0.10.1 — 2016-09-25
- 0.9.4 — 2016-08-16
- 0.9.3 — 2016-08-16
- 0.9.2 — 2014-04-02
- 0.9.1 — 2014-04-02
- 0.9.0 — 2014-04-02
- 0.1.3 — 2012-01-15
- 0.1.2 — 2012-01-14
- 0.1.1 — 2012-01-14
- … 1 more at https://npm.io/package/bogart-handlebars/versions

## README

# Bogart Handlebars

Bogart Middleware to load a directory hierarchy of views.

    npm install bogart-handlebars --save

In your app:

```javascript
var bogartHandlebars = require('bogart-handlebars');

var app = bogart.app();
app.use(bogartHandlebars(Path.join(__dirname, 'views')));
```

Middleware executed after bogartHandlebars will have `views` and
`respond` services available. The views service is an object whose
property hierarchy matches the directory hierarchy of the views.

Directory contents starting with underscore e.g. *_layout.html* are
registered as partials with their full path name.

Example:

Figure A, Directory Hierarchy

    views
      |-layouts
        |-_main.hbt
      |-public
        |-index.hbt

**_main.hbt** will be registered as the partial 'layouts/main'.

**index.hbt** will be available from `views.public.index`.

## `respond` service

Middleware executed after bogart-handlebars will have `respond` available
as a service.

    /**
     * Create a Bogart response with a body of a handlebars view.
     * @param {Function} view  The handlebars view from the `view` service.
     * @param {Object} locals  Template variables for the handlebars template.
     * @param {Object} options Overrides for the response. Common values: status, headers.
     * @returns {Object} A Bogart response.
     */
    respond(view, locals, options)

Example:

```javascript
var bogartHandlebars = require('bogart-handlebars');

var router = bogart.router();
router.get('/', function (views, respond) {
  return respond(views.public.index, { title: 'Hello World' });
});

var app = bogart.app();
app.use(bogartHandlebars(path.join(__dirname, 'views')));
app.use(router);
```

## Cross-cutting locals

It is possible to add to the locals passed to the view by `respond` in
a cross-cutting manner with the `onCreateLocals` event. Register a callback
to this event:

```javascript
bogartHandlebars(path.join(__dirname, 'views'))
  .onCreateLocals(function (session) {
    return { user: session('user') }
  });
```

This example adds a `user` parameter from `session` to the locals
of every view that `respond` renders.

`onCreateLocals` is chainable.

---
_Source: https://npm.io/package/bogart-handlebars · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
