问题
I'm using <% include components/aside.ejs %>
or <% include components/head.ejs %>
somewhere in my code without any problem. But when I use include
in a for loop like this
<%
for (var i = 0; i < 20; i++) {
include components/head.ejs;
}
%>
, I get Unexpected identifier in [file path] while compiling ejs
.
Is there any obvious mistake that I'm not noticing?
回答1:
To fix a breaking change, as of EJS 3.x, the syntax for an include has gone from <%- include components/head.ejs %>
to <%- include('components/head.ejs'); %>
.
回答2:
Include the template tags <%
and %>
on every line, like this:
<% for (var i = 0; i < 20; i++){ %>
<%- include components/head.ejs %>
<% }; %>
回答3:
You can try this one.
<% for (var i = 0; i < 20; i++){ %>
<%- include('component/footer') %>
<% }; %>
来源:https://stackoverflow.com/questions/33429895/ejs-unexpected-identifier-when-using-include-in-for-loop