{% if pageCount > 1 %}
    <nav aria-label="Pagination">
        {% set classAlign = (align is defined) ? " text-#{align}" : '' %}
        <ul class="pagination{{ classAlign }}">
            {% if previous is defined %}
                <li class="pagination-previous">
                    <a rel="prev" href="{{ path(route, knp_pagination_query(query, previous, options)) }}">
                        {{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}
                    </a>
                </li>
            {% else %}
                <li class="pagination-previous disabled">
                    {{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}
                </li>
            {% endif %}

            {% if startPage > 1 %}
                <li>
                    <a href="{{ path(route, knp_pagination_query(query, 1, options)) }}">1</a>
                </li>
                {% if startPage == 3 %}
                    <li>
                        <a href="{{ path(route, knp_pagination_query(query, 2, options)) }}">2</a>
                    </li>
                {% elseif startPage != 2 %}
                    <li class="ellipsis"></li>
                {% endif %}
            {% endif %}

            {% for page in pagesInRange %}
                {% if page != current %}
                    <li>
                        <a href="{{ path(route, knp_pagination_query(query, page, options)) }}">
                            {{ page }}
                        </a>
                    </li>
                {% else %}
                    <li class="current">{{ page }}</li>
                {% endif %}
            {% endfor %}

            {% if pageCount > endPage %}
                {% if pageCount > (endPage + 1) %}
                    {% if pageCount > (endPage + 2) %}
                        <li class="ellipsis"></li>
                    {% else %}
                        <li>
                            <a href="{{ path(route, knp_pagination_query(query, (pageCount - 1), options)) }}">
                                {{ pageCount - 1 }}
                            </a>
                        </li>
                    {% endif %}
                {% endif %}
                <li>
                    <a href="{{ path(route, knp_pagination_query(query, pageCount, options)) }}">{{ pageCount }}</a>
                </li>
            {% endif %}

            {% if next is defined %}
                <li class="pagination-next">
                    <a rel="next" href="{{ path(route, knp_pagination_query(query, next, options)) }}">
                        {{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}
                    </a>
                </li>
            {% else %}
                <li class="pagination-next disabled">
                    {{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}
                </li>
            {% endif %}
        </ul>
    </nav>
{% endif %}
