Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
/ gulp-twig Public archive
forked from backflip/gulp-twig

Compile twig.js templates in a gulp stream

Notifications You must be signed in to change notification settings

wearelucid/gulp-twig

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gulp-twig

Uses twig.js to compile Twig templates.

Usage

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/'));
});

Options

options.data

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;
}

options.includes

Type: String|Array

Single or array of globs of includes to be registered.

options.getIncludeId

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.

About

Compile twig.js templates in a gulp stream

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%