在客户端呈现 EJS 部分 - 找不到包含文件错误

Render EJS partial on client side - Could not find the include file error

提问人:dfdf1 提问时间:10/14/2022 最后编辑:dfdf1 更新时间:10/14/2022 访问量:47

问:

我正在尝试更新 socket.io 一些部分的数据。 我在 partials 包中有一个名为 info_card.ejs 的部分,它有两个参数:title 和 info。我尝试渲染以下代码:

   <% info_cards.forEach(function(card) { %>
         <%- include("../partials/info_card", card) %>
   <% }); %>

第一次渲染是由服务器进行的,当我尝试在客户端(在 js 脚本中)渲染时,如下所示:

const update_info_cards =
            [
                {title: "title1", info: "info1"},
                {title: "title1", info: "info2"}
            ]
  
        var html = ejs.render(`<% info_cards.forEach(function(card) { %>
            <%- include("../partials/info_card", card) %>
            <% }); %>`, {info_card: update_info_cards })

我收到此错误:

    1| <% info_cards.forEach(function(card) { %>
 >> 2|             <%- include("../partials/info_card", card) %>
    3|             <% }); %>

Could not find the include file "../partials/info_card"

不知道如何解决,我已经尝试更改路径很长时间了,但仍然收到此错误。我也试图在互联网上查找一些答案 - 找不到任何答案。

  • 我看到我不能在客户端包含,那么有什么选择,因为我真的看不到我多次处理卡的所有html代码?

谢谢!

node.js EJS 客户端

评论


答: 暂无答案