shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.

Home Page:http://npm.im/gulp-hb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nested partials don't work

alexdevero opened this issue · comments

Partials don' work when using nested folder. Partials right inside partials folder work (footer.hbs, nav.hbs). Partials inside homepage folder don't work (home-hero.hbs, home-main.hbs).

Project structure:

src
┗━ templates/
      ┣━ index.hbs
      ┗━ partials/
          ┣━ footer.hbs
          ┗━ nav.hbs
          ┗━ homepage/
              ┣━ home-hero.hbs
              ┗━ home-main.hbs

Gulp task:

gulp.task('hb:dev', () => {
  const hbStream = handlebars()
    .partials('./src/templates/partials/**/*.hbs')
    .helpers('./src/templates/helpers/**/*.js')
    .data('./src/templates/data/**/*.{js,json}')

  return gulp.src('./src/templates/index.hbs')
    .pipe(plumber())
    .pipe(prune({
      dest: hbDestPath, ext: [
        '.hbs',
        '.html'
      ]
    }))
    .pipe(changed(hbDestPath))
    .pipe(hbStream)
    .pipe(rename({
      extname: '.html'
    }))
    .pipe(gulp.dest(hbDestPath))
    .pipe(browserSync.stream({
      match: '**/*.html'
    }))
})

Error:

 Error in plugin 'gulp-hb'
Message:
    The partial home-hero could not be found
Details:
    description: undefined
    fileName: E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\src\templates\index.hbs
    lineNumber: undefined
    number: undefined
Stack:
Error: The partial home-hero could not be found
    at Object.invokePartial (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\handlebars\lib\handlebars\runtime.js:258:11)
    at Object.invokePartialWrapper [as invokePartial] (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\handlebars\lib\handlebars\runtime.js:47:39)
    at Object.eval (eval at createFunctionContext (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\handlebars\lib\handlebars\compiler\javascript-compiler.js:236:23), <anonymous>:14:28)
    at main (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\handlebars\lib\handlebars\runtime.js:152:32)
    at ret (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\handlebars\lib\handlebars\runtime.js:155:12)
    at ret (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\handlebars\lib\handlebars\compiler\compiler.js:513:21)
    at E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\handlebars-wax\src\handlebars-wax.js:216:10
    at DestroyableTransform._transform (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\gulp-hb\src\gulp-hb.js:94:31)
    at DestroyableTransform.Transform._read (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\readable-stream\lib\_stream_transform.js:182:10)
    at DestroyableTransform.Transform._write (E:\Devero-Laboratories\WEB\Supernova Studio\supernova-main-page-design\node_modules\readable-stream\lib\_stream_transform.js:170:83)

Nested partials contain the folder structure in the partial name based on the glob parent. I think you're looking for:

{{> homepage/home-hero}}

To see the registered partials, helpers, decorators, and top-level data keys, use the debug option:

const hbStream = handlebars({ debug: true })
    .partials('./src/templates/partials/**/*.hbs')
    .helpers('./src/templates/helpers/**/*.js')
    .data('./src/templates/data/**/*.{js,json}')

Thank you! I knew it I have to use the folder structure pattern */*! Thank you very much @shannonmoeller.

My pleasure.