# engine-handlebars

> Handlebars engine, consolidate.js style but with enhancements. This works with Assemble, express.js, engine-cache or any application that follows consolidate.js conventions.

Latest version **1.1.0** (published 2020-08-12) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-08-12 |
| First published | 2014-09-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Jon Schlinkert |
| Maintainers | doowb, jonschlinkert |
| Keywords | assemble, compile, consolidate, engine, express, handlebars, hbs, helper, partial, process, render, template, templates |

## Links

- npm: https://www.npmjs.com/package/engine-handlebars
- Repository: https://github.com/jonschlinkert/engine-handlebars
- Issues: https://github.com/jonschlinkert/engine-handlebars/issues
- npm.io page: https://npm.io/package/engine-handlebars

## Dependencies (1)

- [kind-of](https://npm.io/package/kind-of.md) ^6.0.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-08-12
- 1.0.0 — 2018-11-11
- 0.8.2 — 2017-02-21
- 0.8.1 — 2017-02-21
- 0.8.0 — 2015-09-18
- 0.7.0 — 2015-09-18
- 0.6.1 — 2015-02-20
- 0.6.0 — 2015-02-20
- 0.5.0 — 2015-02-19
- 0.4.1 — 2015-02-03
- 0.4.0 — 2014-11-21
- 0.3.0 — 2014-10-24
- 0.2.0 — 2014-09-06

## README

# engine-handlebars [![NPM version](https://img.shields.io/npm/v/engine-handlebars.svg?style=flat)](https://www.npmjs.com/package/engine-handlebars) [![NPM monthly downloads](https://img.shields.io/npm/dm/engine-handlebars.svg?style=flat)](https://npmjs.org/package/engine-handlebars) [![NPM total downloads](https://img.shields.io/npm/dt/engine-handlebars.svg?style=flat)](https://npmjs.org/package/engine-handlebars) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/engine-handlebars.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/engine-handlebars)

> Handlebars engine, consolidate.js style but with enhancements. This works with Assemble, express.js, engine-cache or any application that follows consolidate.js conventions.

Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save engine-handlebars
```

## Heads up!

There were major [breaking changes in v1.0!](#release-history).

## Usage

```js
const handlebars = require('handlebars');
const engine = require('engine-handlebars')(handlebars);
console.log(engine);
```

The `engine` object that is returned has the following properties:

* `name` - the name of the engine: `handlebars`, used for engine detection in other libraries.
* `instance` - your instance of handlebars
* `compile` - async compile method
* `compileSync` - sync compile method
* `render` -  async render method
* `renderSync` - sync render method

## API

### [.compile](index.js#L49)

Compile `file.contents` with `handlebars.compile()`. Adds a compiled `.fn()` property to the given `file`.

**Params**

* `file` **{Object}**: File object with `contents` string or buffer.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Promise}**

**Example**

```js
engine.compile({ contents: 'Jon {{ name }}' })
  .then(file => {
    console.log(typeof file.fn) // 'function'
  });
```

### [.render](index.js#L70)

Render `file.contents` with the function returned from `.compile()`.

**Params**

* `file` **{Object}**: File object with `contents` string or buffer.
* `locals` **{Object}**: Locals to use as contents to render the string.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Promise}**

**Example**

```js
engine.render({ contents: 'Jon {{ name }}' }, { name: 'Schlinkert' })
  .then(file => {
    console.log(file.contents.toString()) // 'Jon Schlinkert'
  });
```

### [.compileSync](index.js#L116)

Compile `file.contents` with `handlebars.compile()`. Adds a compiled `.fn()` property to the given `file`.

**Params**

* `file` **{Object}**: File object with `contents` string or buffer.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Object}**: Returns the file object.

**Example**

```js
let file = engine.compileSync({ contents: 'Jon {{ name }}' });
console.log(typeof file.fn) // 'function'
```

### [.renderSync](index.js#L146)

Render `file.contents` with the function returned from `.compile()`.

**Params**

* `file` **{Object}**: File object with `contents` string or buffer.
* `locals` **{Object}**: Locals to use as contents to render the string.
* `options` **{Object}**: Options with partials and helpers.
* `returns` **{Object}**: Returns the file object.

**Example**

```js
let file = engine.renderSync({ contents: 'Jon {{ name }}' }, { name: 'Schlinkert' });
console.log(file.contents.toString()) // 'Jon Schlinkert'
```

## Release History

### v1.0.0

* The main export is now a function that takes an instance of handlebars.
* `renderFile` and `__express` have been removed.
* `.compile` and `.render` now return a promise.
* `.compileSync` and `.renderSync` may be used for sync operations.
* All methods now expect a `file` object with a `.contents` property (string or buffer).

### v0.8.0

* `renderFile` now expects a [vinyl](https://github.com/gulpjs/vinyl) file.
* The old renderFile method is now exposed on `engine.__express`

### v0.7.0

* updated to handlebars 0.4.0

## About

<details>
<summary><strong>Contributing</strong></summary>

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

</details>

<details>
<summary><strong>Running Tests</strong></summary>

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

</details>

<details>
<summary><strong>Building docs</strong></summary>

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

</details>

### Related projects

You might also be interested in these projects:

* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
* [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers): More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… [more](https://github.com/helpers/handlebars-helpers) | [homepage](https://github.com/helpers/handlebars-helpers "More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.")
* [template-helpers](https://www.npmjs.com/package/template-helpers): Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… [more](https://github.com/jonschlinkert/template-helpers) | [homepage](https://github.com/jonschlinkert/template-helpers "Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or any engine that supports helper functions.")
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.")

### Contributors

| **Commits** | **Contributor** |  
| --- | --- |  
| 32 | [jonschlinkert](https://github.com/jonschlinkert) |  
| 18 | [doowb](https://github.com/doowb) |  

### Author

**Jon Schlinkert**

* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)

### License

Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 11, 2018._

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