Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ejs - "Unexpected identifier" when using include in for loop

Tags:

node.js

ejs

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?

like image 653
Mehdi Hoseini Avatar asked Oct 30 '15 06:10

Mehdi Hoseini


2 Answers

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'); %>.

like image 117
Steven Ventimiglia Avatar answered Nov 07 '22 19:11

Steven Ventimiglia


You can try this one.

    <% for (var i = 0; i < 20; i++){ %>
     <%- include('component/footer') %>
    <% }; %>
like image 42
Devang Avatar answered Nov 07 '22 18:11

Devang