Symfony 4-自定义KnpPaginator分页模板?

Symfony 4-自定义KnpPaginator分页模板?,symfony,templates,pagination,customization,Symfony,Templates,Pagination,Customization,我希望自定义一个KnpPaginator分页模板,使其如下所示: 这是一个简单的模板通常,我只想显示我所在的范围,与最大和上一个和下一个按钮 我发现我们可以制作自己的模板。所以我想从那些已经存在的东西中汲取灵感,但我根本不明白它们是如何工作的,它们看起来彼此如此不同,我发现很难找到我的方法,找到我必须使用的东西 有人能帮我吗 我有这个基本模板,但我不知道如何编辑它以拥有自己的自定义模板: {# /** * @file * Twitter Bootstrap v4-beta.2 Slidin

我希望自定义一个KnpPaginator分页模板,使其如下所示:

这是一个简单的模板通常,我只想显示我所在的范围,与最大和上一个和下一个按钮

我发现我们可以制作自己的模板。所以我想从那些已经存在的东西中汲取灵感,但我根本不明白它们是如何工作的,它们看起来彼此如此不同,我发现很难找到我的方法,找到我必须使用的东西

有人能帮我吗

我有这个基本模板,但我不知道如何编辑它以拥有自己的自定义模板:

{#
/**
 * @file
 * Twitter Bootstrap v4-beta.2 Sliding pagination control implementation.
 *
 * View that can be used with the pagination module
 * from the Twitter Bootstrap CSS Toolkit
 * https://getbootstrap.com/docs/4.0/components/pagination/
 *
 */
#}
{% if pageCount > 1 %}
    <nav>
        {% set classAlign = (align is not defined) ? '' : align=='center' ? ' justify-content-center' : (align=='right' ? ' justify-content-end' : '') %}
        {% set classSize = (size is not defined) ? '' : size=='large' ? ' pagination-lg' : (size=='small' ? ' pagination-sm' : '') %}
        <ul class="pagination{{ classAlign }}{{ classSize }}">

            {% if previous is defined %}
                <li class="page-item">
                    <a class="page-link" rel="prev" href="{{ path(route, query|merge({(pageParameterName): previous})) }}">&laquo;&nbsp;{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
                </li>
            {% else %}
                <li class="page-item disabled">
                    <span class="page-link">&laquo;&nbsp;{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</span>
                </li>
            {% endif %}

            {% if startPage > 1 %}
                <li class="page-item">
                    <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): 1})) }}">1</a>
                </li>
                {% if startPage == 3 %}
                    <li class="page-item">
                        <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): 2})) }}">2</a>
                    </li>
                {% elseif startPage != 2 %}
                    <li class="page-item disabled">
                        <span class="page-link">&hellip;</span>
                    </li>
                {% endif %}
            {% endif %}

            {% for page in pagesInRange %}
                {% if page != current %}
                    <li class="page-item">
                        <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a>
                    </li>
                {% else %}
                    <li class="page-item active">
                        <span class="page-link">{{ page }}</span>
                    </li>
                {% endif %}

            {% endfor %}

            {% if pageCount > endPage %}
                {% if pageCount > (endPage + 1) %}
                    {% if pageCount > (endPage + 2) %}
                        <li class="page-item disabled">
                            <span class="page-link">&hellip;</span>
                        </li>
                    {% else %}
                        <li class="page-item">
                            <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): (pageCount - 1)})) }}">{{ pageCount -1 }}</a>
                        </li>
                    {% endif %}
                {% endif %}
                <li class="page-item">
                    <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): pageCount})) }}">{{ pageCount }}</a>
                </li>
            {% endif %}

            {% if next is defined %}
                <li class="page-item">
                    <a class="page-link" rel="next" href="{{ path(route, query|merge({(pageParameterName): next})) }}">{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}&nbsp;&raquo;</a>
                </li>
            {% else %}
                <li  class="page-item disabled">
                    <span class="page-link">{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}&nbsp;&raquo;</span>
                </li>
            {% endif %}
        </ul>
    </nav>
{% endif %}
{#
/**
*@file
*TwitterBootstrapV4 beta.2滑动分页控制实现。
*
*可与分页模块一起使用的视图
*来自Twitter引导CSS工具包
* https://getbootstrap.com/docs/4.0/components/pagination/
*
*/
#}
{如果页面计数大于1%,则为%1}
{%set classAlign=(未定义对齐)?“”:对齐=='center'?'justify content center':(对齐=='right'?'justify content end':“”)%}
{%set classSize=(未定义大小)?'':大小='large'?'pagination lg':(大小='small'?'pagination sm':'')%}
    {%如果定义了上一个%}
  • {%else%}
  • &拉阔;{{'label_previous'{}trans({},'KnpPaginatorBundle')}
  • {%endif%} {%如果起始页>1%}
  • {%如果起始页==3%}
  • {%elseif startPage!=2%}
  • &hellip;
  • {%endif%} {%endif%} {pagesInRange%中的页面的%s} {%if页面!=当前%}
  • {%else%}
  • {{page}
  • {%endif%} {%endfor%} {%if pageCount>endPage%} {%if pageCount>(endPage+1)%} {%if pageCount>(endPage+2)%}
  • &hellip;
  • {%else%}
  • {%endif%} {%endif%}
  • {%endif%} {%如果定义了next%}
  • {%else%}
  • {{'label_next'{trans({},'KnpPaginatorBundle')}}»;
  • {%endif%}
{%endif%}
我相信您正在寻找类似以下代码的内容。您需要根据需要调整按钮格式。 使用标准引导CSS,我的示例应该呈现类似的内容:

还要确保将config/packages/knp_paginator.yaml中的分页模板路径调整为 IE:分页:“your/path/inside/templates/directory/your_template.yaml”

{%if pageCount>1%}
{{totalCount}的{firstItemNumber}}到{lastItemNumber}}项
{%如果定义了上一个%}
{%else%}
> 
{%endif%}
{%endif%}

完美!就是这样!非常感谢!:)
{% if pageCount > 1 %}
    items {{ firstItemNumber }} to {{ lastItemNumber }} of {{totalCount}}
    {% if previous is defined %}
            <a type="button" class="btn btn-secondary" rel="prev" href="{{ path(route, query|merge({(pageParameterName): previous})) }}">{{'<'}}</a>
    {% else %}
            <button type="button" class="btn btn-secondary" disabled><</button>
    {% endif %}
    {% if next is defined %}
            <a type="button" class="btn btn-secondary" rel="next" href="{{ path(route, query|merge({(pageParameterName): next})) }}"> > </a>
    {% else %}
        <button type="button" class="btn btn-secondary" disabled> > </button>
    {% endif %}
{% endif %}