# gulp-compile-handlebars

> Compile Handlebars templates to file - gulp plugin

Latest version **0.6.1** (published 2015-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-compile-handlebars
pnpm add gulp-compile-handlebars
yarn add gulp-compile-handlebars
bun add gulp-compile-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.6.1 |
| Published | 2015-12-12 |
| First published | 2014-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 100 |
| Author | Kaanon MacFarlane |
| Maintainers | kaanon |
| Keywords | gulp, handlebars, gulp-plugin, template, compile, html, rendering |

## Links

- npm: https://www.npmjs.com/package/gulp-compile-handlebars
- Repository: https://github.com/kaanon/gulp-compile-handlebars
- Issues: https://github.com/kaanon/gulp-compile-handlebars/issues
- npm.io page: https://npm.io/package/gulp-compile-handlebars

## Dependencies (3)

- [through2](https://npm.io/package/through2.md) ^0.6.3
- [gulp-util](https://npm.io/package/gulp-util.md) ^3.0.3
- [handlebars](https://npm.io/package/handlebars.md) >=3.0.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.6.1 (latest) — 2015-12-12
- 0.3.2 (0.3.2) — 2014-06-06
- 0.3.1 (0.3.1) — 2014-06-06
- 0.3.0 (0.3.0) — 2014-06-06
- 0.5.1 — 2015-12-08
- 0.6.0 — 2015-12-08
- 0.5.0 — 2015-05-13
- 0.4.4 — 2014-12-20
- 0.4.3 — 2014-11-17
- 0.3.3 — 2014-09-22
- 0.2.0 — 2014-04-08
- 0.1.1 — 2014-03-15

## README

# gulp-compile-handlebars
Forked from [gulp-template](https://github.com/sindresorhus/gulp-template)
Inspired by [grunt-compile-handlebars](https://github.com/patrickkettner/grunt-compile-handlebars)

> Compile [Handlebars templates](http://www.handlebarsjs.com/)

## Install

Install with [npm](https://npmjs.org/package/gulp-compile-handlebars)

```
npm install --save-dev gulp-compile-handlebars
```


## Example

### `src/hello.handlebars`

```handlebars
{{> header}}
<p>Hello {{firstName}}</p>
<p>HELLO! {{capitals firstName}}</p>
{{> footer}}
```

### `src/partials/header.handlebars`

```handlebars
<h1>Header</h1>
```

### `gulpfile.js`

```js
var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var rename = require('gulp-rename');

gulp.task('default', function () {
	var templateData = {
		firstName: 'Kaanon'
	},
	options = {
		ignorePartials: true, //ignores the unknown footer2 partial in the handlebars template, defaults to false
		partials : {
			footer : '<footer>the end</footer>'
		},
		batch : ['./src/partials'],
		helpers : {
			capitals : function(str){
				return str.toUpperCase();
			}
		}
	}

	return gulp.src('src/hello.handlebars')
		.pipe(handlebars(templateData, options))
		.pipe(rename('hello.html'))
		.pipe(gulp.dest('dist'));
});
```

### `dist/hello.html`

```html
<h1>Header</h1>
<p>Hello Kaanon</p>
<p>HELLO! KAANON</p>
<footer>the end</footer>
```

## Options

- __ignorePartials__ : ignores any unknown partials. Useful if you only want to handle part of the file
- __partials__ : Javascript object that will fill in partials using strings
- __batch__ : Javascript array of filepaths to use as partials
- __helpers__: javascript functions to stand in for helpers used in the handlebars files
- __compile__: compile options. See [handlebars reference](http://handlebarsjs.com/reference.html#base-compile) for possible values

## handlebars.Handlebars

You can access the Handlebars library from the `handlebars.Handlebars` property.

```js
var handlebars = require('gulp-compile-handlebars');
var safestring = new handlebars.Handlebars.SafeString('<strong>HELLO! KAANON</strong>');
```

## handlebars.Handlebars

You can access the Handlebars library from the `handlebars.Handlebars` property.

```js
var handlebars = require('gulp-compile-handlebars');
var safestring = new handlebars.Handlebars.SafeString('<strong>HELLO! KAANON</strong>');
```

## Works with gulp-data

Use gulp-data to pass a data object to the template based on the handlebars file being processed.
If you pass in template data this will be extended with the object from gulp-data.

See [gulp-data](https://www.npmjs.org/package/gulp-data) for usage examples.

## License

[MIT](http://opensource.org/licenses/MIT) © [Kaanon MacFarlane](http://kaanon.com)

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