我正在尝试通过express处理表单的get请求,我的代码如下:
app.get('/newsletter', function(req, res){
res.render('newsletter');
});
发出请求时出现此错误:
> Error: Missing helper: 'section'
> at new Exception (G:\express\node_modules\handlebars\dist\cjs\handlebars\exception.js:13:41)
> at Object.<anonymous> (G:\express\node_modules\handlebars\dist\cjs\handlebars\base.js:57:13)
> at Object.eval (eval at createFunctionContext (G:\express\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23),
> <anonymous>:18:213)
> at G:\express\node_modules\handlebars\dist\cjs\handlebars\runtime.js:86:31
> at G:\express\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:465:21
> at ExpressHandlebars._renderTemplate (G:\express\node_modules\express3-handlebars\lib\express-handlebars.js:339:22)
> at ExpressHandlebars.renderTemplate (G:\express\node_modules\express3-handlebars\lib\express-handlebars.js:196:18)
> at fn (G:\express\node_modules\async\lib\async.js:582:34)
> at Immediate.<anonymous> (G:\express\node_modules\async\lib\async.js:498:34)
> at runCallback (timers.js:789:20)
答案 0 :(得分:1)
弄清楚了......我需要将辅助对象添加到我的车把配置中。...以下是一些更正了我的代码的
const handlebars = require('express3-handlebars').create(
{defaultLayout:'main',
helpers:{
section:function(name, options){
if(!this._sections){this._sections = {}};
this._sections[name] = options.fn(this);
return null;
};
}});