Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populating HTML with JSON data #1

Open
jgatjens opened this issue Oct 13, 2016 · 2 comments
Open

Populating HTML with JSON data #1

jgatjens opened this issue Oct 13, 2016 · 2 comments

Comments

@jgatjens
Copy link
Owner

jgatjens commented Oct 13, 2016

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
Copy link

i dont care.

@rpswallace
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants