Search code examples
gulpgulp-wrap

Gulp-wrap: how to use dynamic template files?


gulp-wrap is an excellent tool allowing me to use template layout to populate HTML files:

gulp.src('/my/project/**/*.html')
    .pipe(wrap({ src: '/my/project/layout.tpl' }))
    .pipe(gulp.dest('/my/webapp/'));

Now my situation is: for some HTML files (say, files with name containing 'special'), I need to use a different template layout special.tpl. How to incorporate into the workflow above? I have searched but got no result.

Please help, thanks.


Solution

  • Solved the problem by using gulp-switch:

    function getLayout(file) {
        return file.path.indexOf('special') >= 0 ? 'special' : 'common';
    }
    
    return gulp.src(dpwFiles.pages)
        .pipe(gulpSwitch(getLayout, {
            common: wrap({src: 'layout.tpl' }),
            special: wrap({src: 'special.tpl' })
        }))
        .pipe(gulp.dest('/my/webapp'));