Skip to content

Instantly share code, notes, and snippets.

@pbanigo
Created Jun 24, 2022
Embed
What would you like to do?
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