我有一个 EJS 模板,其中包含
<%- include('other-template'); %>
。
当我使用 Express.js 渲染模板时,效果很好。
但是,当我使用
await ejs.renderFile('main.ejs', {async: true})
执行此操作时,我得到的只是 [object Promise]
字符串,而不是看到渲染的子模板。
如何让EJS正确渲染子模板?
使用
async:true
,include
也会返回一个承诺,因此请尝试等待每个部分:在每个 await
上添加 include
:
<%- await include('other-template'); %>