如何在另一个局部EJS中包含局部?

时间:2018-07-25 18:23:35

标签: javascript html templates ejs

我正在尝试使用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>

2 个答案:

答案 0 :(得分:0)

使用Express 3.0:

<%- include myview.ejs %>

路径是相对于包含文件的调用方的,而不是相对于使用

设置的views目录的相对路径
app.set("views", "path/to/views");

EJS includes

答案 1 :(得分:0)

如果您的方向相同,请使用

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

如果要返回,请使用双点。

<% include ../parts/header%>
<% include ../parts/section%>
相关问题