Module

rendering.template_functions.pagination_helpers

Pagination helper functions for templates.

Provides 3 functions for building pagination controls.

Functions

register
Register pagination helper functions with Jinja2 environment.
2 None
def register(env: Environment, site: Site) -> None

Register pagination helper functions with Jinja2 environment.

Parameters 2

Name Type Default Description
env Environment
site Site
paginate_items
Paginate a list of items.
3 dict[str, Any]
def paginate_items(items: list[Any], per_page: int = 10, current_page: int = 1) -> dict[str, Any]

Paginate a list of items.

Parameters 3

Name Type Default Description
items list[Any]

List to paginate

per_page int 10

Items per page (default: 10)

current_page int 1

Current page number (1-indexed)

Returns

dict[str, Any]

Dictionary with pagination data

page_url
Generate URL for a pagination page.
2 str
def page_url(base_path: str, page_num: int) -> str

Generate URL for a pagination page.

Parameters 2

Name Type Default Description
base_path str

Base path (e.g., "/posts/")

page_num int

Page number

Returns

str

URL for that page

page_range
Generate page range with ellipsis for pagination controls.
3 list[int | None]
def page_range(current_page: int, total_pages: int, window: int = 2) -> list[int | None]

Generate page range with ellipsis for pagination controls.

Parameters 3

Name Type Default Description
current_page int

Current page number

total_pages int

Total number of pages

window int 2

Number of pages to show around current (default: 2)

Returns

list[int | None]

List of page numbers with None for ellipsis