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

Front Matter in partials? #44

Closed spacedawwwg closed 8 years ago

spacedawwwg commented 8 years ago

is there a way to access front matter from within a partial?

In the layout I can access {{frontMatter.title}} but when I try the same from within a partial it does not work?

I have also tried {{../frontMatter.title}} to no prevail.

Is there any way to do this at all?

shannonmoeller commented 8 years ago

Some options:

1) Use partial parameters:

<!-- someFile.html -->
{{> somePartial title=frontMatter.title}}

<!-- somePartial.hbs -->
{{title}}

2) Use the @file reference:

<!-- someFile.html -->
{{> somePartial}}

<!-- somePartial.hbs -->
{{@file.data.frontMatter.title}}

3) Use the handlebars-layouts embed helper instead of the partial syntax:

<!-- someFile.html -->
{{{embed "somePartial"}}}

<!-- somePartial.hbs -->
{{frontMatter.title}}
shannonmoeller commented 8 years ago

Closing due to inactivity and no similar reported bugs. Feel free to reopen if you're still having issues!

spacedawwwg commented 8 years ago

Sorry for not responding. Using partial parameters worked for me, the @file reference didn't.

Happy using partial parameters though.