Render/precompile Lodash/Underscore templates
npm install gulp-template> Render/precompile Lodash/Underscore templates
Issues with the output should be reported on the Lodash issue tracker.
``sh`
npm install --save-dev gulp-template
`erb`Hello <%= name %>
`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:
`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'))
);
`
`html`Hello Sindre
Render a template using the provided data.
Precompile a template for rendering dynamically at a later time.
#### data
Type: object
Data object used to populate the text.
#### options
Type: object
You can also provide your own interpolation string for custom templates.
`html`Hello {{ name }}
`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'))
);
`
`html`Hello Sindre
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}))