shannonmoeller / handlebars-layouts

Handlebars helpers which implement layout blocks similar to Jinja, Nunjucks (Swig), Pug (Jade), and Twig.

Home Page:http://npm.im/handlebars-layouts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extending partial causes error (handlebars.compile is not a function)

martyan opened this issue · comments

Trying to implement handlebars-layouts, I get error when extending a partial:
ERROR in Template execution failed: TypeError: handlebars.compile is not a function

  1. I registered the helpers and partials (handlebars.js):
const Handlebars = require('handlebars/runtime')
const layouts = require('handlebars-layouts')
const fs = require('fs')

Handlebars.registerHelper(layouts(Handlebars))

const partial = fs.readFileSync('./src/components/partial.hbs', 'utf-8')
Handlebars.registerPartial('partial', partial)

module.exports = Handlebars

  1. Added the handlebars runtime to handlebars-loader options in webpack config (webpack.config.js):
/* ... */
test: /\.hbs$/,
loader: 'handlebars-loader',
options: {
    runtime: SRC_PATH + '/helpers/handlebars',
    helperDirs: [SRC_PATH + '/helpers']
}
/* ... */

  1. Partial component partial.hbs
  2. Extending partial webpack-layouts.hbs


What am I missing?
When I register the partial as follows, no error is appearing, but the partial is not extended (handlebars.js)

Handlebars.registerPartial('partial', () => {
  return partial
})


Repro repository:
https://github.com/martyan/start-coding/tree/handlebars-layouts

Commit with handlebars-layouts implementation:
martyan/start-coding@ad75830

What was the solution to this?