Skip to content

Instantly share code, notes, and snippets.

@jmcclell
Created January 6, 2012 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jmcclell/1569257 to your computer and use it in GitHub Desktop.
Save jmcclell/1569257 to your computer and use it in GitHub Desktop.
Django Paginator Bootstrap Compatible Template Snippet
{#
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:"&larr; Previous"}}</a>
</li>
{% else %}
<li class="prev disabled">
<a href="#">{{previous_label|default:"&larr; 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 &rarr;"}}</a>
</li>
{% else %}
<li class="next disabled">
<a href="#">{{next_label|default:"Next &rarr;"}}</a>
</li>
{% endif %}
{% endif %}
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment