-
-
Save hitrust/5e255cd3572e4b96093676cfaa68fa81 to your computer and use it in GitHub Desktop.
Flask/Jinja2 macro for rendering pagination in a template with Bootstrap components. Can center the component by wrapping in <nav class="text-center">.
This file contains hidden or 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
| {% macro render_pagination(pagination, endpoint) %} | |
| <ul class="pagination"> | |
| {% if pagination.has_prev %} | |
| <li> | |
| <a href="{{ url_for(endpoint, page=pagination.prev_num) }}" aria-label="Previous"> | |
| <span aria-hidden="true">«</span> | |
| </a> | |
| </li> | |
| {% endif %} | |
| {% for p in pagination.iter_pages(left_edge=1, left_current=2, right_current=3, right_edge=1) %} | |
| {% if p %} | |
| {% if p != pagination.page %} | |
| <li> | |
| <a href="{{ url_for(endpoint, page=p) }}">{{ p }}</a> | |
| </li> | |
| {% else %} | |
| <li class="active"> | |
| <a href="{{ url_for(endpoint, page=p) }}">{{ p }}</a> | |
| </li> | |
| {% endif %} | |
| {% else %} | |
| <li class="disabled"> | |
| <span class="ellipsis">…</span> | |
| </li> | |
| {% endif %} | |
| {% endfor %} | |
| {% if pagination.has_next %} | |
| <li> | |
| <a href="{{ url_for(endpoint, page=pagination.next_num) }}" aria-label="Next"> | |
| <span aria-hidden="true">»</span> | |
| </a> | |
| </li> | |
| {% endif %} | |
| </ul> | |
| {% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment