把手错误与护照蒸汽

时间:2017-06-09 09:37:47

标签: node.js express handlebars.js passport.js

给我一​​个错误,我无法显示头像和蒸汽名称

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 });
});
<img src='{{user.photos[2].value}}' alt="Profile Avatar"/>
<span>{{{user.dispalyName}}}</span>

错误

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)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,而photos[2]中的索引导致了错误。您可以使用来自同一用户对象的user._json值来绕过此问题,如下所示:

<img src="{{user._json.avatarfull}}" alt="Profile Avatar"/>

此工作正常,图片的网址与user.photos中的网址相同。