【问题标题】:ejs - "Unexpected identifier" when using include in for loopejs - 在 for 循环中使用包含时的“意外标识符”
【发布时间】:2020-01-09 15:51:55
【问题描述】:

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

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

,我得到Unexpected identifier in [file path] while compiling ejs

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

【问题讨论】:

    标签: node.js ejs


    【解决方案1】:

    为了修复一个重大更改,从 EJS 3.x 开始,包含的语法已从 &lt;%- include components/head.ejs %&gt; 变为 &lt;%- include('components/head.ejs'); %&gt;

    【讨论】:

      【解决方案2】:

      你可以试试这个。

          <% for (var i = 0; i < 20; i++){ %>
           <%- include('component/footer') %>
          <% }; %>
      

      【讨论】:

        【解决方案3】:

        在每一行包括模板标签&lt;%%&gt;,像这样:

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

        【讨论】:

        • 在尝试此答案时,这会从“意外标识符”变为“参数列表后的语法错误:缺少)”。 #TrashFire
        猜你喜欢
        • 2012-12-27
        • 2020-12-27
        • 2017-02-25
        • 2020-02-09
        • 1970-01-01
        • 2016-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多