ejs - “Unexpected identifier” when using include in for loop

自古美人都是妖i 提交于 2020-03-20 06:54:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!