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

Multiple directories for partials #13

Closed loremipson closed 9 years ago

loremipson commented 9 years ago

I'm not quite sure when this issue came about exactly, and it might ultimately be within handlebars-layouts, but I have multiple directories set up for partials (one for layouts) and it doesn't seem to be working anymore.

Here's my gulp-hb pipe:

.pipe(hb({
  data: '_data/**/*.{js,json}',
  helpers: [
    'node_modules/handlebars-layouts',
  ],
  partials: [
    '_partials/**/*.hbs',
    '_layouts/**/*.hbs',
  ]
}))

This was working perfectly at one point, but now upon compiling, it reports, "Error: Missing partial: 'base'" if base.hbs is in my _layouts directory.

If I move base.hbs into _partials it works again. Which is great, but ideally, I'd have them in separate directories still to avoid potential confusion.

shannonmoeller commented 9 years ago

Partials are named according to the directory structure. All common parent directories are trimmed and extensions removed. So:

hb({ partials: ['./_partials/**/*.hbs'] });

with

`- _partials/
   |- foo.hbs
   `- bar.hbs

would register foo and bar as paritals. While:

hb({
    partials: [
        './_partials/**/*.hbs'
        './_layouts/**/*.hbs'
    ]
});

with

|- _partials/
|  |- foo.hbs
|  `- bar.hbs
`- _layouts/
   |- baz.hbs
   `- qux.hbs

would register _partials/foo, _partials/bar, _layouts/baz, and _layouts/qux. I'll soon be adding a debug option which will console.log the data object keys, helpers names, and partial names to help make this more obvious.

loremipson commented 9 years ago

Ah hah.. the one thing I didn't actually try.

So it seems that I only need to specify that level if it's in the _layouts directory. Things inside _partials are still rendering fine with: {{> filename }}. {{> _partials/filename }} seems to work as well, but it's not erroring with the less verbose version. edit: Never mind, not sure what confused me before, but I do indeed need to specify {{> _partials/filename }}

I noticed that my json data doesn't seem to be pulling in anymore either, would this be related to the same issue? With my above mentioned code, I have this file:

|- _data/
|    |- site.json

Which I am then just pulling into my templates with: {{site.title}}. Similarly, nothing is pulling in with that now, where it was before. Is there an extra step in place now?

Thanks!

loremipson commented 9 years ago

And I just read in previous issues about the data now requiring the filename as of 2.0, so in my current case, I need to call {{site.site.title}}. Which is .. ugly, but easy to change.

Closing this as it's a non-issue. Thanks for the help!