jgatjens / frontend

Gulp, es6, layouts, partials, etc
1 stars 0 forks source link

Populating HTML with JSON data #1

Open jgatjens opened 7 years ago

jgatjens commented 7 years ago

Install gulp-data: npm i -D gulp-data

In the gulpfile.babel import the module and the data you want to pass to the templates.

 import data from 'gulp-data';
 import jsonData from './src/path/to/json';

Edit the nunjucks task to add the data

gulp.task('nunjucks', () => {
  // Gets .html and .nunjucks files in pages
  return gulp.src(src.nunjucks)
      // Adding data to Nunjucks
      .pipe(data(function() {
        return jsonData;
      }))
      // Renders template with nunjucks
      .pipe(nunjucksRender({
        path: [src.templates]
      }))
      // output files in app folder
      .pipe(gulp.dest(src.root));
});
Marcotss commented 7 years ago

i dont care.

rpswallace commented 7 years ago

Nice!! Thanks! @Marcotss Grow up! :D