[Question]How make it work with Handlebars?
vladgal opened this issue · 5 comments
I made the code and it sending me an error
`router.get('/', function(req, res) {
res.render('index', { user: req.user }, { title: 'Express' });
});
router.get('/tos', function(req, res) {
res.render('tos', { user: req.user }, { title: 'Terms of Service' });
});`
<img src='{{user.photos[2].value}}' alt="Avatar Image" /> <span>{{user.displayName}}</span>
Error
`C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\express-handlebars\lib\utils.js:18
callback(reason);
^
TypeError: callback is not a function
at Immediate. (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\express-handlebars\lib\utils.js:18:13)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)`
You're not using the correct syntax for res.render()
. You should specify the template (which you're doing correctly), then a single object for the properties you wish to pass to that template. You're instead passing in 2 objects, and the second one is in the place of where an optional callback should go. Do something like this instead:
router.get('/', function(req, res) {
res.render('index', { title: 'Express', user: req.user });
});
router.get('/tos', function(req, res) {
res.render('tos', { title: 'Terms of Service', user: req.user });
});
There no error but the its not display the image and the name
Error: Parse error on line 36: ... <img src='{{user.photos[2].value}}' a -----------------------^ Expecting 'ID', got 'INVALID' at Parser.parseError (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\handlebars\dist\cjs\handlebars\compiler\parser.js:267:1 9) at Parser.parse (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\handlebars\dist\cjs\handlebars\compiler\parser.js:336:30) at HandlebarsEnvironment.parse (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\handlebars\dist\cjs\handlebars\compiler\base. js:46:43) at compileInput (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:514:19) at ret (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:523:18) at ExpressHandlebars._renderTemplate (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\express-handlebars\lib\express-handleba rs.js:247:12) at ExpressHandlebars.<anonymous> (C:\Users\VladG\Desktop\Tutorials\Express Web\CSGOGamble\node_modules\express-handlebars\lib\express-handlebars.j s:173:21)
Well, this isn't really the place for handlebars-specific issues. Try asking for help on the handlebars repository.
I need to make a var named user or its inside passport already?