6.0.0 • Published 11 months ago

gulp-template v6.0.0

Weekly downloads
25,209
License
MIT
Repository
github
Last release
11 months ago

gulp-template

Render/precompile Lodash/Underscore templates

Issues with the output should be reported on the Lodash issue tracker.

Install

npm install --save-dev gulp-template

Usage

src/greeting.html

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

gulpfile.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 to inject the data:

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

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

Tip

You can also provide your own interpolation string for custom templates.

src/greeting.html

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

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

<h1>Hello Sindre</h1>
accucode-wp-starter@mycolorway/vestdev-agnitio-clislush-hughes-wp-starterslush-accucode-wp-starterslush-slush-accucode-wp-startervtex-boilerplate@acanto/workflow-laravel-frontendslush-vtex-boilerplatevitepress-dg-clislush-aws-samslush-phonegapslush-nodewebkit-express-nedbslush-boilerplateslush-nodewebkit-indexeddb@zrosenbauer/slush-reactorslush-reactorslush-wordpress-generator@dotedu/ivx-web-story-forgegrommet-ocgrommet-phetaslush-api-blueprint-focus-boosterslush-ui5slush-fringe-reactyan-element-uuuubrowserify-template@infinitebrahmanuniverse/nolb-gulp-tslush-new-componentslush-gulp-sassslush-gulpfile-frontng2-lib-proj@everything-registry/sub-chunk-1812slush-ivomarsanjugsjugs-vueconduit-sasscommular-bb-generatecreate-vlibcreate-vlib-fdcorgi-biucreate-frontend-componentday-spacsbcetsc-customexec-commandespinaffalconfecoolecma6_boilerplatefoxtrel-commend-installgulp-cocktailgulp-email-marketing-helpergulp-gridfwgrommet-udacitygulp-binarta-templategulp-stackgulp-ps-tasksgenerator-package-cookinggenerator-package-cpinggenerator-package-xdcgenerator-alloyteam-simpleglup-package-chameleonglup-package-lucasfoxtrel-command-installgeomanglpgulphygulp4-ps-tasksgulp-zkflow-angulardong-builddong-inithull-connector-templatehence-clihence-clienthsing-vueionic2-custom-iconsilegojacks-angular4-clipotionsellerpoke-try-hardpoke-try-harderpbiviz-clipjinitslush-airframe@enjin/ionic1@ersinfotech/slush-mobile@ersinfotech/slush-react@ersinfotech/slush-worker@ersinfotech/slush-express@ersinfotech/slush-graphql@ersinfotech/slush-library@elfin-fe/svg-manlorryliutestatomiclithium-sdklfalegolaravel-elixir-templateismart-gulpfilekdui1
6.0.0

11 months ago

5.0.0

7 years ago

4.0.0

8 years ago

3.1.0

9 years ago

3.0.0

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.1.2

10 years ago

0.1.1

11 years ago

0.1.0

11 years ago