Created
January 6, 2012 06:02
-
-
Save jmcclell/1569257 to your computer and use it in GitHub Desktop.
Django Paginator Bootstrap Compatible Template Snippet
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
{# | |
This template snippet will take a page from a django Paginator and create a Twitter Bootstrap pagination HTML snippet. | |
To use: | |
{% include "path/to/django-paginator-bootstrap.html with page=contextVar only %} | |
Optional variables: | |
alignment - Accepts "centered" or "right". Other values have no affect. Default is left aligned. | |
hide_previous - Accepts "true" to hide | |
previous_label - Changes the Previous label text | |
hide_next - Accepts "true" to hide | |
next_label - Changes the Next label text | |
page_param - Changes the name of the page parameter (defaults to "page") | |
}# | |
<div class="pagination {% if alignment == "centered" %}pagination-centered{% endif %}{% if alignment == "right" %}pagination-right{% endif %}"> | |
<ul> | |
{% if hide_previous != "true" %} | |
{% if page.has_previous %} | |
<li class="prev"> | |
<a href="{{url_suffix|default:"?page="}}{{page.previous_page_number}}">{{previous_label|default:"← Previous"}}</a> | |
</li> | |
{% else %} | |
<li class="prev disabled"> | |
<a href="#">{{previous_label|default:"← Previous"}}</a> | |
</li> | |
{% endif %} | |
{% endif %} | |
{% for pagenum in page.paginator.page_range %} | |
<li{% if page.number == pagenum %} class="active"{% endif %}> | |
<a href="{{url_suffix|default:"?page="}}{{pagenum}}">{{pagenum}}</a> | |
</li> | |
{% endfor %} | |
{% if hide_next != "true" %} | |
{% if page.has_next %} | |
<li class="next"> | |
<a href="{{url_suffix|default:"?page="}}{{page.next_page_number}}">{{next_label|default:"Next →"}}</a> | |
</li> | |
{% else %} | |
<li class="next disabled"> | |
<a href="#">{{next_label|default:"Next →"}}</a> | |
</li> | |
{% endif %} | |
{% endif %} | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment