Parsing json data in to Assemble 0.17.1 via Gulp

99 views Asked by At

My Json data doesn´t get parsed. Assemble v0.17.1, Gulp v3.9.1

I have this task in my Gulpfile.js:

var app = assemble();

app.helpers(helpers());

gulp.task('load', function(cb) {
  app.layouts(pathDir.layouts + '/*.hbs');
  app.pages(pathDir.pages + '/**/*.hbs');
  app.partials(pathDir.partials + '/**/*.hbs');
  app.data(pathDir.data + '/*.json');
  cb();
});

gulp.task('assemble', ['load'], function() {
  return app.toStream('pages')
    .pipe(plumber())
    .pipe(app.renderFile())
    .pipe(extname())
    .pipe(app.dest(pathDir.dev));
});

my test.json file looks like this:

{"title": "Das ist ein Test"} 

My testpage.hbs looks like this:

<div style="font-size:32px;">AAAA
  <span style="background-color:#f00;">{{test.title}}</span>
  BBB
</div>

In my rendered html i only get:

<div style="font-size:32px;">AAAA<span style="background-color:#f00;"></span>BBB</div>

What am I doing wrong?

1

There are 1 answers

4
doowb On

Try passing the namespace option to the app.data method:

app.data(pathDir.data + '/*.json', {namespace: true});

It was mentioned in the changelog section that the .data method is using base-data, but the api section hasn't been updated yet. The namespacing option is described here.