Created
April 11, 2018 18:07
-
-
Save neenjaw/9235392cde6c1c0b258a248b397faa1c to your computer and use it in GitHub Desktop.
Pagination template implemented in EJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row text-center"> | |
<% if (pages && pages > 0) { %> | |
<ul class="pagination text-center"> | |
<% if (current == 1) { %> | |
<li class="disabled"><a>First</a></li> | |
<% } else { %> | |
<li><a href="/campgrounds<%if(search){%>?search=<%=search%><%}%>">First</a></li> | |
<% } %> | |
<% if (current == 1) { %> | |
<li class="disabled"><a>«</a></li> | |
<% } else { %> | |
<li><a href="/campgrounds?page=<%= Number(current) - 1 %><%if(search){%>&search=<%=search%><%}%>">«</a></li> | |
<% } %> | |
<% var i = (Number(current) > 5 ? Number(current) - 4 : 1) %> | |
<% if (i !== 1) { %> | |
<li class="disabled"><a>...</a></li> | |
<% } %> | |
<% for (; i <= (Number(current) + 4) && i <= pages; i++) { %> | |
<% if (i == current) { %> | |
<li class="active"><a><%= i %></a></li> | |
<% } else { %> | |
<li><a href="/campgrounds?page=<%= i %><%if(search){%>&search=<%=search%><%}%>"><%= i %></a></li> | |
<% } %> | |
<% if (i == Number(current) + 4 && i < pages) { %> | |
<li class="disabled"><a>...</a></li> | |
<% } %> | |
<% } %> | |
<% if (current == pages) { %> | |
<li class="disabled"><a>»</a></li> | |
<% } else { %> | |
<li><a href="/campgrounds?page=<%= Number(current) + 1 %><%if(search){%>&search=<%=search%><%}%>">»</a></li> | |
<% } %> | |
<% if (current == pages) { %> | |
<li class="disabled"><a>Last</a></li> | |
<% } else { %> | |
<li><a href="/campgrounds?page=<%= pages %><%if(search){%>&search=<%=search%><%}%>">Last</a></li> | |
<% } %> | |
</ul> | |
<% } %> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment