Uses twig.js to compile Twig templates.
First, install gulp-twig
as a development dependency:
npm install --save-dev gulp-twig@git+https://[email protected]/backflip/gulp-twig.git
Then, add it to your gulpfile.js
:
var twig = require('gulp-twig'),
path = require('path'),
rename = require('gulp-rename');
gulp.task('html', function(){
gulp.src(['./source/*.twig'])
.pipe(twig({
data: {
title: 'hello'
},
includes: [
'./source/layouts/*.twig',
'./source/includes/*.twig'
],
getIncludeId: function(filePath) {
return path.relative('./source', filePath);
}
}))
.pipe(rename({
extname: '.html'
}))
.pipe(gulp.dest('./build/'));
});
Type: Object|Function
An object of data to pass to the compiler. If of type function
, the Vinyl file object is passed as argument:
data: function(file) {
return file.data;
}
Type: String|Array
Single or array of globs of includes to be registered.
Type: Function
Transformation function for template ID. If omitted, the file path is used. In the example above, source/layouts/layout.twig
would be registered as layout/layout.twig
.