Node.js 如何在hapi.js ejs布局中获得多个内容区域?
我想在一个模板中定义信息,该模板在包含hapi.js的布局中呈现。例如: layout.htmlNode.js 如何在hapi.js ejs布局中获得多个内容区域?,node.js,ejs,hapijs,hapijs-vision,Node.js,Ejs,Hapijs,Hapijs Vision,我想在一个模板中定义信息,该模板在包含hapi.js的布局中呈现。例如: layout.html <html> <head> <title><%- contentFor('title') %></title> </head> <body> <%- content %> </body> </html> conten
<html>
<head>
<title><%- contentFor('title') %></title>
</head>
<body>
<%- content %>
</body>
</html>
contentFor('title', 'My title')
<h1>My content</h1>
index.html
<html>
<head>
<title><%- contentFor('title') %></title>
</head>
<body>
<%- content %>
</body>
</html>
contentFor('title', 'My title')
<h1>My content</h1>
contentFor('title','My title')
我的内容
对我来说,重要的是,无论它如何工作,不同的布局内容都是在模板中定义的,而不是在管线级别传递的。这可能吗?是的,这一点都不明显。我可以通过以下方式做到这一点:
//templates/my_template.html
在布局中引用对象
//layouts/layout.html
如您所见,您可以将文本或整个标记传递给布局。希望这有帮助
// layouts/layout.html
<html>
<head>
<title><%- layoutContent.title %></title>
<%- layoutContent.meta %>
</head>
<body>
<%- content %>
</body>
</html>