2

如何将 Jade 与 Hapi 框架一起使用?

特别是,如何使用 Jade 表单和 Hapi 函数发送数据。

谢谢

4

1 回答 1

4

Have you looked at the Hapi tutorials? There's one specifically for views: http://hapijs.com/tutorials/views. Furthermore, there's an example made for Jade here: https://github.com/spumko/hapi/blob/master/examples/views/jade/index.js

So from the documentation, you would configure your server similarly to this:

var options = {
    views: {
        engines: { jade: require('jade') },
        path: __dirname + '/templates',
        compileOptions: {
            pretty: true
        }
    }
};

Then when rendering the view, you can pass data to the template like so:

reply.view('index', {
    title: 'examples/views/jade/index.js | Hapi ' + Hapi.version,
    message: 'Index - Hello World!'
});

There's also another great tutorial on Hapi which has a part on views: https://github.com/spumko/makemehapi

Hope that helps

于 2014-07-14T22:10:38.407 回答