Closed VincentVToscano closed 9 years ago
Version 2.0 of gulp-hb
introduced a breaking change for the data attribute. It's now using require-glob
to pull in data which takes filenames into account. Try updating your template to include the filename (without the extension) of your data, like so:
<div id="Dreamscape{{dreamscape_data.id}}" class="hello">
{{#each dreamscape_data.projs}}
<div id="itemNumber{{id}}" tabindex="0" class="porthole {{addClass}}" style="background:{{bkgd}}">{{id}}</div>
{{/each}}
</div>
Or wrap it in a {{#with}} block:
{{#with dreamscape_data}}
<div id="Dreamscape{{id}}" class="hello">
{{#projs}}
<div id="itemNumber{{id}}" tabindex="0" class="porthole {{addClass}}" style="background:{{bkgd}}">{{id}}</div>
{{/projs}}
</div>
{{/with}}
That worked great @shannonmoeller. I used the second method (#with) to process the template. Thank you for reviewing my ticket.
using #with didn't fix this for me but for my use case I don't need a context anyway.
Any way to get hb to use any data in the data object without having to have to refer to the file from which it came?
I already have a work around which is read my json else where and pass the object to .data which works fine for my use case (changing json file names)
@dkebler What you've described is exactly what I'd recommend in your case!
.data(require('./path/to/data.json'))
Version 2.0 of gulp-hb introduced a breaking change for the data attribute. It's now using require-glob to pull in data which takes filenames into account. Try updating your template to include the filename (without the extension) of your data, like so:
<div id="Dreamscape{{dreamscape_data.id}}" class="hello">
{{#each dreamscape_data.projs}}
<div id="itemNumber{{id}}" tabindex="0" class="porthole {{addClass}}" style="background:{{bkgd}}">{{id}}</div>
{{/each}}
</div>
Or wrap it in a {{#with}} block:
{{#with dreamscape_data}}
<div id="Dreamscape{{id}}" class="hello">
{{#projs}}
<div id="itemNumber{{id}}" tabindex="0" class="porthole {{addClass}}" style="background:{{bkgd}}">{{id}}</div>
{{/projs}}
</div>
{{/with}}
It would be nice to have this in the README. 👍
gulp-hb
is a gulp
wrapper around handlebars-wax
which has a section on registering data. I think it would be better to update the documentation in that README and leave this one pretty generic. Feel free to open an issue or PR over there. Thanks!
This is a question/help, I wish I could label it that… I am trying process 1 handlebar template with 1 JSON file. The output file, does not show any of the data from the JSON file. What am I doing wrong?
gulp task:
Template before:
Template processed/output file:
JSON file:
Thanks for the help.