{% if pages > 1 %}
    <ul class="btn-group">
        {% if currentPage > 1 %}
            <li class="btn btn-md">
                <a href="{{ safe_path(route, routeParams|merge({page: currentPage - 1})) }}">
                    {{- 'Précédent' -}}
                </a>
            </li>
        {% endif %}

        {% set begin = max(1, currentPage - 2) %}
        {% set end = min(pages, currentPage + 2) %}

        {% if begin > 1 %}
            <li class="btn btn-md hidden md:flex">
                <a href="{{ safe_path(route, routeParams|merge({page: 1})) }}">
                    {{- '1' -}}
                </a>
            </li>

            <li class="btn btn-md hidden md:flex">…</li>
        {% endif %}

        {% for page in range(begin, end)  %}
            <li class="btn btn-md hidden md:flex {{ currentPage == page ? 'btn-active' : '' }}">
                <a href="{{ safe_path(route, routeParams|merge({page: page})) }}">
                    {{- page -}}
                </a>
            </li>
        {% endfor %}

        {% if end < pages %}
            <li class="btn btn-md hidden md:flex">…</li>

            <li class="btn btn-md hidden md:flex">
                <a href="{{ safe_path(route, routeParams|merge({page: pages})) }}">
                    {{- pages -}}
                </a>
            </li>
        {% endif %}

        {% if currentPage < pages %}
            <li class="btn btn-md">
                <a href="{{ safe_path(route, routeParams|merge({page: currentPage + 1})) }}">
                    {{- 'Suivant' -}}
                </a>
            </li>
        {% endif %}
    </ul>
{% endif %}
