Skip to content

Instantly share code, notes, and snippets.

@pbanigo
Created June 24, 2022 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbanigo/469c90be581b2fdb641e4a85f6154d94 to your computer and use it in GitHub Desktop.
Save pbanigo/469c90be581b2fdb641e4a85f6154d94 to your computer and use it in GitHub Desktop.
EJS index file with dynamic data
<!-- add header -->
<%- include('includes/_header') %>
<!-- end header -->
<!-- Main section -->
<main id="main">
<a href="/add-drug">
<button id="new">New Drug <i class="fas fa-pills"></i></button>
</a>
<h2>Drugs</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Drug Name</th>
<th>Tablets per Card</th>
<th>Tablets per Pack</th>
<th>Taken per Day</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<!-- Loop through drugs -->
<% for(let i = 0; i < drugs.length; i++) {%>
<tr>
<td><%= i + 1 %></td>
<td><%= drugs[i].name %></td>
<td><%= drugs[i].card %></td>
<td><%= drugs[i].pack %></td>
<td><%= drugs[i].perDay %></td>
<td>
<a href="/update-drug?id=<%= drugs[i]._id%>">
<span class='fa fa-edit'></span>
</a>
<a class="delete" data-id=<%= drugs[i]._id%> ><!-- give each delete button a unique ID -->
<span class='fa fa-trash'></span>
</a>
</td>
</tr>
<% } %> <!-- End loop -->
</tbody>
</table>
</main>
<!-- End main section -->
<!-- add footer -->
<%- include('includes/_footer') %>
<!-- end footer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment