unic / estatico

[DEPRECATED] Estático – Static site generator for frontend unicorns
Other
121 stars 18 forks source link

Handlebars context is wrong (@root not working in pages) #36

Closed swey closed 7 years ago

swey commented 7 years ago

The context of the pages is wrong, because @root is empty and does not include any data. The data is only accessible as file-specific data via @file.data.

A reason could be that dataEach is not supported by gulp-hb/handlebars-wax anymore: https://github.com/unic/estatico/blob/develop/gulp/html/default.js#L187

Also see: https://github.com/shannonmoeller/gulp-hb/tree/v5.0.0#template-context

backflip commented 7 years ago

So you are using .data() to specify global data? Otherwise @root would be empty anyway, right?

swey commented 7 years ago

@root references to the most upper data level and it worked quite well in the old estatico version, where the data was assigned with dataEach based on file.data.

But in the latest version dataEach was removed and actually the main data object is empty, only file.data is filled. But the file.data context is only an alternative context of gulp-hb and is not intent to be the main data source.

backflip commented 7 years ago

So dataEach did just assign everything from file.data into the @root? Judging from the new docs, it doesn't seem to be possible to expose file-specific data globally anymore.

swey commented 7 years ago

For more information on @root see: http://handlebarsjs.com/reference.html

In the gulp-hb task the data of the handlebars template needs to be set via .hb({data: {}) in the object or with the extra method .hb().data({}), at the moment no data is set at all (only in the alternative file.data context).

I saw that you asked some questions in the gulp-hb repo some time ago, where they told you to use dataEach and that made the job. I tried to fix it in a different way and to add dataEach again, but I'm no gulp expert at all, so it did not work so far.

backflip commented 7 years ago

I don't think we can solve this. .hb({data: {}) would have to be called outside of the stream and .hb().data({}) does not provide us access to the currently streamed file.

backflip commented 7 years ago

I think you will have to ask gulp-hb to add an additional option for this (similar to dataEach, having the currently streamed file as an argument) and pass the data to templateOptions.data.root or context

backflip commented 7 years ago

PR openend in gulp-hb: https://github.com/shannonmoeller/gulp-hb/pull/48

swey commented 7 years ago

Version 6.0.0 of gulp-hb fixes the problem 🎉

Will create a PR as soon the latest version is listed on npm