user6145162
user6145162

Reputation:

Batch nested templates in subdirectories using gulp-compile-handlebars

I'm using gulp compileHandlebars to compile my handlebars templates and create a page using json data and that's working great... Problem is I want to nest my handlebars templates in subdirectories but when I do this the batch process cant find the templates anymore after I add: **/*.handlebars to the batch path. See below:

gulp.task('compileHandlebars', function () {
    delete require.cache[require.resolve('./src/layout.json')]
    var buildSettings = require('./src/layout.json');
    var templateData = buildSettings,
    options = {
        batch : ['./src/assets/templates/**/*.handlebars']
    }

    gulp.src('./src/index.handlebars')
        .pipe(handlebars(templateData, options))
        .pipe(rename('index.html'))
        .pipe(cleanhtml())
        .pipe(gulp.dest('./dist'))
        .pipe(livereload());
});

Upvotes: 0

Views: 639

Answers (1)

JohnnyK
JohnnyK

Reputation: 41

The docs on npm say that batch requires an array of file paths but the example shows an array with a directory path. Your example is using blob syntax which won't work. It doesn't look like that batch will recursively look into sub-directories either... so I think you will have to make an array that includes a parent directory path for each handlebars file.

Its a bummer, I know. But you could probably automate the process of retrieving the handlebar file paths using gulp-filenames and slice off the filename from each path to get an array of directories.

Upvotes: 1

Related Questions