# gulp-template

> Render/precompile Lodash/Underscore templates

Latest version **6.1.0** (published 2025-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-template
pnpm add gulp-template
yarn add gulp-template
bun add gulp-template
```

## Health

**Score 38/100 (D)** — status: maintenance-mode.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.0 |
| Published | 2025-09-09 |
| First published | 2013-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/gulp-template) |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 287 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | gulpplugin, lodash, underscore, template, compile, html, render, rendering, precompile |

## Links

- npm: https://www.npmjs.com/package/gulp-template
- Repository: https://github.com/sindresorhus/gulp-template
- Homepage: https://github.com/sindresorhus/gulp-template#readme
- Issues: https://github.com/sindresorhus/gulp-template/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/gulp-template

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [gulp-plugin-extras](https://npm.io/package/gulp-plugin-extras.md) ^0.2.2

## 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

- 6.1.0 (latest) — 2025-09-09
- 6.0.0 — 2023-11-01
- 5.0.0 — 2017-12-29
- 4.0.0 — 2016-04-08
- 3.1.0 — 2015-11-14
- 3.0.0 — 2015-02-09
- 2.1.1 — 2015-02-09
- 2.1.0 — 2015-01-24
- 2.0.0 — 2014-12-29
- 1.1.1 — 2014-10-08
- 1.1.0 — 2014-09-11
- 1.0.1 — 2014-09-02
- 1.0.0 — 2014-07-25
- 0.1.2 — 2014-07-25
- 0.1.1 — 2014-01-14
- … 1 more at https://npm.io/package/gulp-template/versions

## README

# gulp-template

> Render/precompile [Lodash/Underscore templates](https://lodash.com/docs#template)

*Issues with the output should be reported on the Lodash [issue tracker](https://github.com/lodash/lodash/issues).*

## Install

```sh
npm install --save-dev gulp-template
```

## Usage

### `src/greeting.html`

```erb
<h1>Hello <%= name %></h1>
```

### `gulpfile.js`

```js
import gulp from 'gulp';
import template from 'gulp-template';

export default () => (
	gulp.src('src/greeting.html')
		.pipe(template({name: 'Sindre'}))
		.pipe(gulp.dest('dist'))
);
```

You can alternatively use [gulp-data](https://github.com/colynb/gulp-data) to inject the data:

```js
import gulp from 'gulp';
import template from 'gulp-template';
import data from 'gulp-data';

export default () => (
	gulp.src('src/greeting.html')
		.pipe(data(() => ({name: 'Sindre'})))
		.pipe(template())
		.pipe(gulp.dest('dist'))
);
```

### `dist/greeting.html`

```html
<h1>Hello Sindre</h1>
```

## API

### template(data, options?)

Render a template using the provided `data`.

### template.precompile(options?)

Precompile a template for rendering dynamically at a later time.

#### data

Type: `object`

Data object used to populate the text.

#### options

Type: `object`

[Lodash `_.template` options](https://lodash.com/docs#template).

## Tip

You can also provide your own [interpolation string](https://lodash.com/docs#template) for custom templates.

### `src/greeting.html`

```html
<h1>Hello {{ name }}</h1>
```

### `gulpfile.js`

```js
import gulp from 'gulp';
import template from 'gulp-template';
import data from 'gulp-data';

export default () => (
	gulp.src('src/greeting.html')
		.pipe(data(() => ({name: 'Sindre'})))
		.pipe(template(null, {
			interpolate: /{{(.+?)}}/gs
		}))
		.pipe(gulp.dest('dist'))
);
```

### `dist/greeting.html`

```html
<h1>Hello Sindre</h1>
```

## Tip

If you need to pass through a file unprocessed (for example, a shell script with `${VAR}` syntax), you can disable interpolation:

```js
.pipe(template(data, {interpolate: false}))
```

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