Extending partial causes error (handlebars.compile is not a function)
martyan opened this issue · comments
Martin Juzl commented
Trying to implement handlebars-layouts
, I get error when extending a partial:
ERROR in Template execution failed: TypeError: handlebars.compile is not a function
- 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
- 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']
}
/* ... */
- Partial component partial.hbs
- 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
Paillat commented
What was the solution to this?