使用快速把手装载助手

时间:2014-10-23 18:56:02

标签: javascript node.js express handlebars.js helper

我正在尝试在我的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);

这是我尝试加载时的页面

enter image description here

Handlebars与Express集成的新功能,所以,我无法弄明白......

1 个答案:

答案 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