简体   繁体   中英

Could not find matching close tag for “<%” error when I try to include the file

When I try to include other .ejs files using the same syntax everything is working perfectly except when I include my _show.ejs file.I dont know where the actual is in the index.ejs or _show.ejs file.

My index.ejs File

<!-- 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 file saved in include folder

<% 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>
<% } %>

Error

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

Could not find matching close tag for "<%". at

    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)```

I think you lose some code. In "_show.ejs" file,

From -

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

To -

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM