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

Standalone partials #5

Closed loremipson closed 9 years ago

loremipson commented 9 years ago

It's entirely possible, and likely that I'm just not grasping handlebars yet, but I can't seem to get standalone .hbs partials to work. I'm not getting an error or anything, they're just not pulling in how I'm expecting them.

I have a couple of directories for partials. One for layouts, ie:

_src/markup/partials/**/*.hbs
_src/markup/layouts/**/*.hbs

Inside my partials directory, I have two files: header.hbs and footer.hbs

I should just be able to call them both in my files, correct? With {{! header.hbs }}? It doesn't seem to be pulling in anything. Am I incorrect in thinking of partials as includes with hbs, or should that be doing what I want?

Here's my gulpfile for reference:

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

gulp.task('html', function(){
  return gulp.src('./_src/markup/content/**/*.{markdown,md,html}')
    .pipe($.frontMatter())
    .pipe($.hb({
      data: './_src/markup/data/**/*.{js,json,yml}',
      helpers: [
        './node_modules/handlebars-layouts',
        './node_modules/handlebars-helpers'
      ],
      partials: [
        './_src/markup/partials/**/*.hbs',
        './_src/markup/layouts/**/*.hbs'
      ]
    }))
    .pipe(gulp.dest('./build/'));
});

Thanks ahead of time!

shannonmoeller commented 9 years ago

Yep, this is a syntax error. I should be clearer in my example.

The {{! ... }} syntax is for comments (https://github.com/wycats/handlebars.js/#comments).

The {{> partialName }} syntax is for partials (https://github.com/wycats/handlebars.js/#partials).

Based on your configuration, give this a try and let me know how it goes:

{{> partials/header }}
loremipson commented 9 years ago

Ah, perfect.. that was it! Thanks for clarifying, this plugin is great by the way, exactly what I've been wanting in a static build with Gulp.

Thanks again

shannonmoeller commented 9 years ago

Awesome! I'm glad this little plugin has been helpful to you.