gulp-compile-handlebars not finding partials

1.2k views Asked by At

I am trying to follow the guidelines for the following gulp plugin: https://www.npmjs.com/package/gulp-compile-handlebars

The gulp function I am using is below which is run by "gulp pages"

gulp.task('pages', function () {

var options = {
    ignorePartials: true, //ignores the unknown footer2 partial in the handlebars template, defaults to false 
    partials : {
        footer : '<footer>the end</footer>'
    },
    batch : ['_hbs'],
    helpers : {
        capitals : function(str){
            return str.toUpperCase();
        }
    }
}
return gulp.src('_hbs/*.hbs')
    .pipe(handlebars(options))
    .pipe(rename(function (path) {
          path.extname = ".html"
        })
     )

    // Flatten structure
    //.pipe(flatten())

    // pretify html structure
   // .pipe(prettify({
   //   indent_size: 4
   // }))

    .pipe(gulp.dest('_hbs/'));

});

I have a page that is loading a partial like so:

{{> _common/header/header}}

And I am receiving the following error:

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: **The partial _common/header/header could not be found**
    at Object.invokePartial (C:\wamp\www\developer\HTML_seed\node_module
s\handlebars\dist\cjs\handlebars\runtime.js:271:11)
    at Object.invokePartialWrapper [as invokePartial] (C:\wamp\www\devel
oper\HTML_seed\node_modules\handlebars\dist\cjs\handlebars\runtime.js:68:39)
    at Object.eval (eval at createFunctionContext (C:\wamp\www\developer
\HTML_seed\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compi
ler.js:254:23), <anonymous>:5:31)
    at main (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dis
t\cjs\handlebars\runtime.js:173:32)
    at ret (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dist
\cjs\handlebars\runtime.js:176:12)
    at ret (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dist
\cjs\handlebars\compiler\compiler.js:525:21)
    at DestroyableTransform._transform (C:\wamp\www\developer\HTML_seed\
node_modules\gulp-compile-handlebars\index.js:131:31)
    at DestroyableTransform.Transform._read (C:\wamp\www\developer\HTML_
seed\node_modules\gulp-compile-handlebars\node_modules\readable-stream\lib\_stre
am_transform.js:184:10)
    at DestroyableTransform.Transform._write (C:\wamp\www\developer\HTML
_seed\node_modules\gulp-compile-handlebars\node_modules\readable-stream\lib\_str
eam_transform.js:172:12)
    at doWrite (C:\wamp\www\developer\HTML_seed\node_modules\gulp-compil
e-handlebars\node_modules\readable-stream\lib\_stream_writable.js:237:10)

Its been almost 6 hours now and I cannot seem to find a solution anywhere on the net, so this is my last resort before I honestly give up.

1

There are 1 answers

0
sildur On BEST ANSWER

You have to replace:

    .pipe(handlebars(options))

by:

    .pipe(handlebars(null, options))