6.0.0 • Published 6 months ago

gulp-template v6.0.0

Weekly downloads
25,209
License
MIT
Repository
github
Last release
6 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-ivomarsancsbcday-spadong-builddong-initrenderer-aj@homerjam/ace-dev-webpackryfecreate-vlibcreate-vlib-fdcreate-frontend-componentcorgi-biuexec-commandshower-clifecoolsiaffalconsecret-service@elfin-fe/svg-man@financial-times/slush-origamirefill-angularrelish-phaser-projectecma6_boilerplatequick-command-initquickstart-yo-yorapid-build@ersinfotech/slush-express@ersinfotech/slush-graphql@ersinfotech/slush-library@ersinfotech/slush-mobile@ersinfotech/slush-react@ersinfotech/slush-worker@enjin/ionic1react-plugretsc-customespinascaffolding-angularsf-gulp-deploysmashersmashing-dev-tool@jelper/buildersmartcontent-cdksrc-genspmh@labshare/lsc@labshare/services-msi-cli@konf/konf@linzebingo/pokeball-cli-servicejacks-angular4-cliionic2-custom-icons@qlniu/dev-clikdui1kduieditor3@ruabick/create-vlibvueui-clijugsjugs-vuesnazziesphinx-sln-scsphinx-solution-scxsphinx-task-scsphinx-task-scxspendesk-collector-template@knot/clisindresorhus.js@kastermester/grommetslush-spaslush-spa-clickbus
6.0.0

6 months ago

5.0.0

6 years ago

4.0.0

8 years ago

3.1.0

8 years ago

3.0.0

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 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

10 years ago

0.1.0

10 years ago