shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.
http://npm.im/gulp-hb
MIT License
147 stars 14 forks source link

Add each 'file' to an array (e.g files) accessible in each page #19

Closed spacedawwwg closed 9 years ago

spacedawwwg commented 9 years ago

If tried to figure tis out, but have come up short.

Is is possible to access each 'file' from within a handlebars page? e.g:

{{#each files}}
<li><a href="{{path}}">{{basename}}</a></li>
{{/each}]
shannonmoeller commented 9 years ago

This is one drawback to gulp. It processes files one at a time, so there's no way to get the whole picture and deliver it to files one by one in a single step. I usually solve this by creating a separate script that gathers the file info I need, then include that in the data: property:

.pipe(hb({
    data: './data/navTree.js',
    ...
}))
spacedawwwg commented 9 years ago

Since switching obver to gulp, everything seems to be more awkward

...back to the drawing board on this one.

shannonmoeller commented 9 years ago

To gulp in general, or to gulp-hb specifically? If the former, you might like broccoli as it works on trees rather than individual files. If the latter, what are your pain points?

spacedawwwg commented 9 years ago

Sorry, gulp in general!! gulp-hb + handlebars-layouts have been my saviours!

gulp-hb is 'exactly' what I need as I use it to create flat 'demo' pages of HTML for clients before integrating them into CMS templates. The only reason I needed an {{#each pages}} like assemble was to create a 'listing` page of all the files (but use the front matter as well)

Apologies for being grumpy in my previous comment.

shannonmoeller commented 9 years ago

No worries! Just didn't want to be the reason you're leaning away from gulp. :) And for what it's worth, there's a gulp plugin called gulp-nav that can do what you'd like to do. I'm not a huge fan because it queues up all of the files and their contents into memory, then re-emits them on flush (ouch). But, it does what you'd like to do. I created an example.