gulp-data icon indicating copy to clipboard operation
gulp-data copied to clipboard

Empty HTML

Open mortensassi opened this issue 7 years ago • 0 comments

My problem is that my views:build task includes the templates before the data gets injected, resulting in a blank html page. What am i doing wrong?

This is my code:

gulp.task('views:build', ['views:templates'] , () => {
  return gulp.src(config.views.src + '*.twig')
      .pipe($.data(function() {
        return JSON.parse(fs.readFileSync('src/data/timber.json'))
      })) // load data from base json file
      .pipe($.twig())
      .pipe(gulp.dest(config.views.tmp))
      .pipe(reload({stream: true}));
});

gulp.task('views:templates', () => {
  return gulp.src(config.views.src + 'templates/*.twig')
      .pipe($.data(function(file) {
        return JSON.parse(fs.readFileSync('src/data/' + path.basename(file.path).replace('.twig', '') 
+ '.json'));
      }))
      .pipe($.twig())
      .pipe(gulp.dest(config.views.tmp))
});

mortensassi avatar Jul 25 '17 16:07 mortensassi