【问题标题】:How to include partials in another partials EJS?如何在另一个部分 EJS 中包含部分?
【发布时间】:2018-07-25 18:23:34
【问题描述】:

我正在尝试使用 EJS 引擎将部分包含在另一个部分中,如下所示:

--First Partials
-----Second Partial

我收到一个错误:

找不到包含文件

谁能帮帮我? 这是我的代码: 第 1 部分

<!DOCTYPE html>
<html lang="ru">
<%- include parts/header %>

    <body>
        <%- include parts/section %>
    </body>

</html>

第 2 部分

<div class="de">
    <img src="img/de.svg" class="development" alt="">
    <%- include parts/postBlog %>
</div>

【问题讨论】:

    标签: javascript html templates ejs


    【解决方案1】:

    如果你在同一个方向,使用那个

    <% include ./parts/header%>
    <% include ./parts/section%>
    

    如果要后退,请使用双点。

    <% include ../parts/header%>
    <% include ../parts/section%>
    

    【讨论】:

      【解决方案2】:

      使用 Express 3.0:

      <%- include myview.ejs %>
      

      路径是相对于包含该文件的调用者的路径,而不是来自设置为的视图目录:

      app.set("views", "path/to/views");
      

      EJS includes

      【讨论】:

        猜你喜欢
        • 2020-01-29
        • 2018-08-16
        • 1970-01-01
        • 2014-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多