PHPackages                             morozgrafix/paginator-twig-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. morozgrafix/paginator-twig-extension

ActiveLibrary[Templating &amp; Views](/categories/templating)

morozgrafix/paginator-twig-extension
====================================

Twig extension to help generate simple paginations in Twig templates.

v0.1.0(7y ago)011MITPHPPHP ^7.0CI failing

Since May 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/morozgrafix/PaginatorTwigExtension)[ Packagist](https://packagist.org/packages/morozgrafix/paginator-twig-extension)[ Docs](https://github.com/morozgrafix/PaginatorTwigExtension)[ RSS](/packages/morozgrafix-paginator-twig-extension/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

PaginatorTwigExtension
======================

[](#paginatortwigextension)

Twig extension to help generate simple paginations in Twig templates.

[![Latest Stable Version](https://camo.githubusercontent.com/3729d18afd9325bfca71da638d0f379a6fa42bef2654438c868cb6b24f4d458c/68747470733a2f2f706f7365722e707567782e6f72672f6d6f726f7a6772616669782f706167696e61746f722d747769672d657874656e73696f6e2f76657273696f6e)](https://packagist.org/packages/morozgrafix/paginator-twig-extension)[![Latest Unstable Version](https://camo.githubusercontent.com/f84c6c454ee8fa4774ff4ae331205ba25efd33fd050c89a155b25538c91ccc3a/68747470733a2f2f706f7365722e707567782e6f72672f6d6f726f7a6772616669782f706167696e61746f722d747769672d657874656e73696f6e2f762f756e737461626c65)](//packagist.org/packages/morozgrafix/paginator-twig-extension)[![Build Status](https://camo.githubusercontent.com/2cfaf2acd30d32459147078289a77f1fc9d89ddb2c3dc0ab0d6e3bf2037cae03/68747470733a2f2f7472617669732d63692e6f72672f6d6f726f7a6772616669782f506167696e61746f7254776967457874656e73696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/morozgrafix/PaginatorTwigExtension)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/357ac7ca89a4b3fd4f98c974d289bafbcde31b1cc887667269a564b4a513fad4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6f726f7a6772616669782f506167696e61746f7254776967457874656e73696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/morozgrafix/PaginatorTwigExtension/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/309d3b0bd70d54d2ec01116f91ef3f0ee9d87bf0bd3c8def651f383ee405d737/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6f726f7a6772616669782f506167696e61746f7254776967457874656e73696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/morozgrafix/PaginatorTwigExtension/?branch=master)[![License](https://camo.githubusercontent.com/bd590351a5198bcdf3be8a13458efb819f258fb6a636669217a91b18d1da6774/68747470733a2f2f706f7365722e707567782e6f72672f6d6f726f7a6772616669782f706167696e61746f722d747769672d657874656e73696f6e2f6c6963656e7365)](https://packagist.org/packages/morozgrafix/paginator-twig-extension)[![composer.lock available](https://camo.githubusercontent.com/4e3aee37fa227693497fee548fc7e34841562c46e7ccc25ccc2cde0a10a7b462/68747470733a2f2f706f7365722e707567782e6f72672f6d6f726f7a6772616669782f706167696e61746f722d747769672d657874656e73696f6e2f636f6d706f7365726c6f636b)](https://packagist.org/packages/morozgrafix/paginator-twig-extension)

Introduction
============

[](#introduction)

This extension helps building pagination in [Twig](https://twig.symfony.com/) templates. It will return an array with all necessary information to quickly display pagination links. It doesn't generate any HTML and it's up to you how you'd like to display it. Example below shows one of the ways of generating pagination compatible with [Bootstrap CSS framework](https://getbootstrap.com/).

[![Example1](../assets/images/example1.png?raw=true)](../assets/images/example1.png?raw=true)

Extension is called with following function and accepts following parameters:

```
paginator(int current_page, int last_page, int num_items, string separator)
```

### Parameters in detail:

[](#parameters-in-detail)

- `current_page` - current page visitor is on
- `last_page` - last page in data set (total number of pages)
- `num_items` - number of items that will be displayed in a pagination strip. *Note:* minimum allowed value is 7 and if even number is passed it will be bumped to next odd number for symmetry.
- `separator` (optional) - custom separator for numbers not visible in pagination strip. Default is set to `...`

#### Basic example:

[](#basic-example)

Calling

```
{% set paginator = paginator(1, 10 , 7) %}
```

will set `paginator` twig variable to:

```
array (
  'curr_page' => 1,
  'last_page' => 10,
  'num_items' => 7,
  'separator' => '...',
  'pagination' => array (
    0 => 1,
    1 => 2,
    2 => 3,
    3 => 4,
    4 => 5,
    5 => '...',
    6 => 10,
  ),
)
```

Installation
============

[](#installation)

Using [Composer](http://getcomposer.org):

```
composer require morozgrafix/paginator-twig-extension
```

Logic in Twig template
======================

[](#logic-in-twig-template)

Following example is compatible with [Bootstrap 4](https://getbootstrap.com/) CSS framework.

```

        {# Optional Prev #}

            Prev

        {# Main Pagination Loop #}
        {% for i in paginator.pagination %}

                {{ i }}

        {% endfor %}

        {# Optional Next #}

            Next

```

Result with optional `Prev`/`Next`:

[![Example2](../assets/images/example2.png?raw=true)](../assets/images/example2.png?raw=true)

Result without `Prev`/`Next`:

[![Example3](../assets/images/example3.png?raw=true)](../assets/images/example3.png?raw=true)

Additional Examples
===================

[](#additional-examples)

Custom separator:

```
{% set paginator = paginator(10, 25 , 11, '¯\_(ツ)_/¯') %}
```

Result:

```
array (
  'curr_page' => 10,
  'last_page' => 25,
  'num_items' => 11,
  'separator' => '¯\\_(ツ)_/¯',
  'pagination' => array (
    0 => 1,
    1 => '¯\\_(ツ)_/¯',
    2 => 7,
    3 => 8,
    4 => 9,
    5 => 10,
    6 => 11,
    7 => 12,
    8 => 13,
    9 => '¯\\_(ツ)_/¯',
    10 => 25,
  ),
)
```

[![Example4](../assets/images/example4.png?raw=true)](../assets/images/example4.png?raw=true)

Even number of items was specified, it gets bumped to next odd number for display symmetry (10 -&gt; 11):

```
{% set paginator = paginator(420, 999 , 10) %}
```

Result:

```
array (
  'curr_page' => 420,
  'last_page' => 999,
  'num_items' => 11,
  'separator' => '...',
  'pagination' => array (
    0 => 1,
    1 => '...',
    2 => 417,
    3 => 418,
    4 => 419,
    5 => 420,
    6 => 421,
    7 => 422,
    8 => 423,
    9 => '...',
    10 => 999,
  ),
)
```

[![Example5](../assets/images/example5.png?raw=true)](../assets/images/example5.png?raw=true)

P.S.
====

[](#ps)

This is my first Twig extension and it was quickly developed while I was working on a bigger project that needed pagination. I'm sure there are some pitfalls and additional features that can be added. Feel free to open an issue or submit a PR with improvements. Thanks. 🙇

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2610d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1007608?v=4)[Sergey Morozov](/maintainers/morozgrafix)[@morozgrafix](https://github.com/morozgrafix)

---

Top Contributors

[![morozgrafix](https://avatars.githubusercontent.com/u/1007608?v=4)](https://github.com/morozgrafix "morozgrafix (20 commits)")

---

Tags

twigpagepaginationpages

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/morozgrafix-paginator-twig-extension/health.svg)

```
[![Health](https://phpackages.com/badges/morozgrafix-paginator-twig-extension/health.svg)](https://phpackages.com/packages/morozgrafix-paginator-twig-extension)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.6M127](/packages/timber-timber)[twig/intl-extra

A Twig extension for Intl

36567.2M320](/packages/twig-intl-extra)[symfony/ux-twig-component

Twig components for Symfony

22017.2M313](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1636.5M115](/packages/symfony-ux-live-component)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

22919.7M81](/packages/twig-cssinliner-extra)[twig/inky-extra

A Twig extension for the inky email templating engine

16613.2M70](/packages/twig-inky-extra)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
