如何渲染 ejs.renderFile 中包含的子模板?

问题描述 投票:0回答:1

我有一个 EJS 模板,其中包含

<%- include('other-template'); %>

当我使用 Express.js 渲染模板时,效果很好。

但是,当我使用

await ejs.renderFile('main.ejs', {async: true})
执行此操作时,我得到的只是
[object Promise]
字符串,而不是看到渲染的子模板。

如何让EJS正确渲染子模板?

node.js ejs
1个回答
0
投票

使用

async:true
include
也会返回一个承诺,因此请尝试等待每个部分:在每个
await
上添加
include

<%- await include('other-template'); %>
© www.soinside.com 2019 - 2024. All rights reserved.