Open fega opened 8 years ago
Same issue here. Locally everything is fine but once i deploy on my DigitalOcean environment i get the same error.
This is how i simply register it.
app.engine('handlebars', exphbs({ defaultLayout: 'main', layoutsDir: path.join(dirname, '/layouts'), partialsDir: path.join(dirname, '/partials') }));
app.set('view engine', 'handlebars');
Hello man, I solved this issue , if you have a partial with the name of a environment variable or HTML tag, you can rename it, and it should works, I had partials called "head" and "footer", for that reason handlebars didn't work
@fega .... thanks.... I just spent an hour trying to figure this out as well.....
I can't get partials to work for the life of me...
It doesn't throw an error or anything it just doesn't work and renders as {{>topbar-responsive}}
Is the folder structure opinionated or something?
app.set('views', path.join(__dirname, '/src/pages'));
app.engine('hbs', hbs({
// defaultLayout: __dirname + '/src/layouts/default.html',
partialsDir: path.join(__dirname, 'src/partials'),
layoutsDir: path.join(__dirname, '/src/layouts')
}));
app.set("view engine", "handlebars");
I'm having the same issue and I'm not sure whan I'm doing wrong:
const exphbs = require('express-handlebars')
const bodyParser = require("body-parser")
const path = require('path');
const app = express()
const hbs = exphbs.create({
extname: 'hbs'
,layoutsDir: path.join(__dirname, 'views/')
,partialsDir: path.join(__dirname, 'views/partials/')
,defaultLayout: 'api-tester'
,helpers: {
formControlTypeMapper: function (value) {
if (value == 'String') return 'text'
if (value == 'Number') return 'number'
if (value == 'Boolean') return 'checkbox'
if (value == 'Date') return 'date'
}
}
})
app.engine('hbs', hbs.engine)
app.set('view engine', 'hbs')
app.set('views', path.join(__dirname, 'views'))
EDIT: I get this error when trying to use the server:
Error: The partial api_tester_css could not be found
at Object.invokePartial (/Users/glara/Desktop/test1/node_modules/handlebars/dist/cjs/handlebars/runtime.js:281:11)
at Object.invokePartialWrapper [as invokePartial] (/Users/glara/Desktop/test1/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
at Object.eval [as main] (eval at createFunctionContext (/Users/glara/Desktop/test1/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:257:23), <anonymous>:6:28)
at main (/Users/glara/Desktop/test1/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32)
at ret (/Users/glara/Desktop/test1/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12)
at ret (/Users/glara/Desktop/test1/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:526:21)
at ExpressHandlebars._renderTemplate (/Users/glara/Desktop/test1/node_modules/express-handlebars/lib/express-handlebars.js:250:12)
at ExpressHandlebars.<anonymous> (/Users/glara/Desktop/test1/node_modules/express-handlebars/lib/express-handlebars.js:173:21)
at <anonymous>
EDIT 2: nevermind, I think the error it's because I'm using snake case when calling the partial (like in the hbs
package), I'll try again tomorrow.
Hello, im using your engine, that works fine in local. but y deployed in heroku and the log throws: how can I solve this?
`2016-03-06T04:28:42.581201+00:00 app[web.1]: GET / 500 149.173 ms - 22
2016-03-06T04:28:42.582060+00:00 app[web.1]: Error: The partial head could not be found
2016-03-06T04:28:42.582073+00:00 app[web.1]: at Object.invokePartial (/app/node_modules/express-handlebars/node_modules/handlebars/dist/cjs/handlebars/runtime.js:266:11)
2016-03-06T04:28:42.582075+00:00 app[web.1]: at Object.invokePartialWrapper as invokePartial
2016-03-06T04:28:42.582076+00:00 app[web.1]: at Object.eval (eval at createFunctionContext (/app /node_modules/express-handlebars/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-com piler.js:254:23),:6:28)
2016-03-06T04:28:42.582077+00:00 app[web.1]: at main (/app/nodemodules/express-handlebars/node modules/handlebars/dist/cjs/handlebars/runtime.js:173:32) 2016-03-06T04:28:42.582077+00:00 app[web.1]: at ret (/app/node_modules/express-handlebars/node_m odules/handlebars/dist/cjs/handlebars/runtime.js:176:12) 2016-03-06T04:28:42.582078+00:00 app[web.1]: at ret (/app/node_modules/express-handlebars/node_m odules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21) 2016-03-06T04:28:42.582079+00:00 app[web.1]: at ExpressHandlebars._renderTemplate (/app/node_mod ules/express-handlebars/lib/express-handlebars.js:247:12) 2016-03-06T04:28:42.582080+00:00 app[web.1]: at ExpressHandlebars. (/app/node_modules
/express-handlebars/lib/express-handlebars.js:173:21)
2016-03-06T04:28:42.792076+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=ekus2.h
erokuapp.com request_id=b0e7daf6-6206-4d53-882b-bb3c413cd7f9 fwd="190.96.137.73" dyno=web.1 connect=
0ms service=10ms status=200 bytes=15313`