未定义车把模板引擎
Handlebars Templating Engine Not Defined
我正在研究 Ethan Brown 的 Web Development with Node & Express: Leveraging the JavaScript Stack。我正在学习第三章,它介绍了有关 Express 的基本概念。正如书中所说,我创建了应用程序 meadowlark.js,但我收到有关 Handlebars 模板引擎的错误:
ReferenceError: handlebars is not defined
at Object.<anonymous> (/PROJECT_STORAGE/site/meadowlark.js:7:26)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
这是我如何设置 Handlebars 的代码以及 meadowlark.js 的其余部分:
var express = require('express');
var app = express();
// setup handlebars view engine
var handlbars = require('express-handlebars').create({ defaultLayout: 'main' });
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('views', __dirname + '/views');
app.set('port', process.env.PORT || 3000);
app.get('/', function(req, res) {
res.render('home');
});
app.get('/about', function(req, res) {
res.type('about');
});
// custom 404 pg
app.use(function(req, res) {
res.status(404);
res.render('404');
});
// custom 500 pg
app.use(function(err, req, res, next) {
//console.error(err.stack);
res.status(500);
res.render('500');
});
app.listen(app.get('port'), function() {
console.log('Express started on localhost:' + app.get('port') + '; press Ctrl-C to terminate.');
});
如何修复我的代码以使 Handlebars 正确初始化并使 handlebars.js 运行?
打字错误var handlbars = require('express-handlebars').create({ defaultLayout: 'main' });
应该是var handlebars
.
专业提示:在 ide.
中使用 linter
我正在研究 Ethan Brown 的 Web Development with Node & Express: Leveraging the JavaScript Stack。我正在学习第三章,它介绍了有关 Express 的基本概念。正如书中所说,我创建了应用程序 meadowlark.js,但我收到有关 Handlebars 模板引擎的错误:
ReferenceError: handlebars is not defined
at Object.<anonymous> (/PROJECT_STORAGE/site/meadowlark.js:7:26)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
这是我如何设置 Handlebars 的代码以及 meadowlark.js 的其余部分:
var express = require('express');
var app = express();
// setup handlebars view engine
var handlbars = require('express-handlebars').create({ defaultLayout: 'main' });
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('views', __dirname + '/views');
app.set('port', process.env.PORT || 3000);
app.get('/', function(req, res) {
res.render('home');
});
app.get('/about', function(req, res) {
res.type('about');
});
// custom 404 pg
app.use(function(req, res) {
res.status(404);
res.render('404');
});
// custom 500 pg
app.use(function(err, req, res, next) {
//console.error(err.stack);
res.status(500);
res.render('500');
});
app.listen(app.get('port'), function() {
console.log('Express started on localhost:' + app.get('port') + '; press Ctrl-C to terminate.');
});
如何修复我的代码以使 Handlebars 正确初始化并使 handlebars.js 运行?
打字错误var handlbars = require('express-handlebars').create({ defaultLayout: 'main' });
应该是var handlebars
.
专业提示:在 ide.
中使用 linter