I'm new to express and handlebars and I'm trying to make some basic templating using partials...
I'm getting a "partial could not be found" error.
dependencies in package.json file
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.15.5",
"hbs": "~4.0.1",
"mongodb": "^3.0.1",
"mongoose": "^5.0.0-rc0",
"morgan": "~1.9.0",
"serve-favicon": "~2.4.5"
}
app.js file snippet
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
// register path to partials
hbs.registerPartials(__dirname + '/views/partials');
index.hbs view file
{{> header }}
{{> left-sidebar }}
{{> right-sidebar }}
I put these partials in a subfolder of the "views" folder in my project.
Any help on what I'm missing?
The missing piece is there is no support for Kebab Case ( Hypen-separated ) in Javascript for a variable. Since partials in handlebars are variables {{> left-sidebar }}
wont work.
Cheers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.