ejs - 在 for 循环中使用包含时出现“意外标识符”

Meh*_*ini 6 ejs node.js

我正在使用<% include components/aside.ejs %><% include components/head.ejs %>在我的代码中的某个地方没有任何问题。但是当我include在这样的 for 循环中使用时

<%
for (var i = 0; i < 20; i++) {
    include components/head.ejs;
}
%>
Run Code Online (Sandbox Code Playgroud)

,我明白了Unexpected identifier in [file path] while compiling ejs

是否有任何我没有注意到的明显错误?

Ste*_*lia 12

要解决重大更改,因为EJS 3.X的,对于语法包括已经从去<%- include components/head.ejs %><%- include('components/head.ejs'); %>


小智 0

在每一行中包含模板标签<%%>,如下所示:

<% for (var i = 0; i < 20; i++){ %>
    <%- include components/head.ejs %>
<% }; %>
Run Code Online (Sandbox Code Playgroud)