当我尝试包含文件时,找不到"<%"错误的匹配关闭标记



当我尝试使用相同的语法包含其他.ejs文件时,除了包含_show.ejs的文件外,一切都很正常。我不知道index.ejs或_show.ejs文件中的实际位置。

我的index.ejs文件

<!-- include header -->
<%- include('include/_header') %>
<!-- /include header -->
<!-- Main Site -->
<main id="site-main">
<div class="container">
<div class="box-nav d-flex justify-between">
<a href="/add-user" class="border-shadow">
<span class="text-gradient">New User <i class="fas fa-user"></i></span>
</a>
</div>
<!-- form handling -->
<form action="/" method="POST">
<table class="table">
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Name</th>
<th>@Email</th>
<th>Gender</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<%- include('include/_show') %>
</tbody>
</table>
</form>
</div>
</main>
<!-- /Main Site -->
<!-- include footer -->
<%- include('include/_footer') %>
<!-- /include footer -->

_show.ejs文件保存在include文件夹中

<% for(var i = 0; i < users.length; i++) { %>
<tr>
<td><%= i + 1 %></td>
<td><%= users[i].name %></td>
<td><%= users[i].email %></td>
<td><%= users[i].gender %></td>
<td><%= users[i].status %></td>
<td>
<a
href="/update-user?id=<%= users[i]._id%>"
class="btn border-shadow update"
>
<span class="text-gradient"><i class="fas fa-pencil-alt"></i></span>
</a>
<a class="btn border-shadow delete" data-id="<%" ="users[i]._id%">
<span class="text-gradient"><i class="fas fa-times"></i></span>
</a>
</td>
</tr>
<% } %>

错误

26|         </thead>
27|         <tbody>
>> 28|           <%- include('include/_show') %>
29|         </tbody>
30|       </table>
31|     </form>

找不到"的匹配结束标记<%&";。在

at Array.forEach (<anonymous>)
at Template.generateSource (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:730:15)
at Template.compile (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:585:12)
at Object.compile (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:396:16)
at handleCache (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:233:18)
at includeFile (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:321:10)
at include (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:690:16)
at eval (eval at compile (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:662:12), <anonymous>:15:17)
at index (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:692:17)
at tryHandleCache (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:272:36)
at View.exports.renderFile [as engine] (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/ejs/lib/ejs.js:489:10)
at View.render (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/express/lib/view.js:135:8)
at tryRender (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/express/lib/application.js:640:10)
at Function.render (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/home/sonwar/Desktop/Programming/NodeJS/crud_app/node_modules/express/lib/response.js:1012:7)```

我认为您丢失了一些代码。在"_show.ejs";文件,

发件人-

<a class="btn border-shadow delete" data-id="<%" ="users[i]._id%">

<a class="btn border-shadow delete" data-id="<%= users[i]._id%>">

最新更新