Monday, 15 May 2017

EJS layout not working in hapi.js

hapi.js docs explain how to use layouts, but when I set things up as described in the docs, the layout is rendered without bringing in the content. The content is rendered correctly (with no layout) when I remove the server layout config.

server

engines: {
    html: require('ejs')
},
relativeTo: __dirname,
path: 'templates',
layout: true,
layoutPath: 'templates/layouts',
...

route

handler: (request, reply) => {
    reply.view('test')

templates/layouts/layout.html

<html>
    <body>
        }
    </body>
</html>

templates/test.html

<h1>Test!</h1>

Rendered content is simply:

}

How can I get the content to render inside the layout?



via dyer

No comments:

Post a Comment