我正在尝试在我的this helper项目中加载Express / Handlebars,但是,我无法让它工作......
这是我的app.js
var express = require('express'),
exphbs = require('express-handlebars');
var app = express();
app.engine('handlebars', exphbs({
defaultLayout: 'main',
helpers: require('handlebars-form-helpers').helpers
}));
app.set('view engine', 'handlebars');
app.get('/', function (req, res) {
res.render('home');
});
app.listen(3000);
这是我尝试加载时的页面
Handlebars与Express集成的新功能,所以,我无法弄明白......
答案 0 :(得分:2)
这应该有效:
var exphbs = require('express-handlebars'),
handlebars = require('handlebars'),
helpers = require('handlebars-form-helpers').register(handlebars);
var hbs = exphbs.create({
helpers: helpers,
defaultLayout: 'main'
});
app.engine('.hbs', hbs.engine);
app.set('view engine', '.hbs');
您可以在此处找到更多信息:https://github.com/ericf/express-handlebars/blob/master/examples/advanced/server.js