如何在Express中使用haml.js呈现HAML模板

我需要在我的Node.js / Express应用程序中呈现HAML模板。 我试图configurationhaml.js作为视图渲染器:

haml = require('hamljs') ... app.set('view engine', 'hamljs') app.engine('.haml', haml.render) 

和我的GET / handeler中的代码:

 options = layout: "layout.haml" locals: message: 'world' res.render('index.haml',options) 

但应用程序不会收到任何数据。

这是haml.js 文档中的另一个例子:

 app.engine('.haml', require('hamljs').renderFile); 

但是没有这样的function。

设置哈姆模板引擎也不适合我。 由于这个话题有几个过时的页面,这可能有点混乱,下面是“手动的方式”,这对我来说很有效:

 var haml = require('hamljs'); var fs = require('fs'); var express = require('express'); var app = express(); app.get('/', function(req, res) { var hamlView = fs.readFileSync('views/home.haml', 'utf8'); res.end( haml.render(hamlView, {locals: {key: 'value'}) ); }); app.listen(process.env.PORT || 3000);