简体   繁体   English

使用自定义模板自定义Pagerfanta分页的布局

[英]Customising the layout of Pagerfanta pagination with a custom template

I have Pagerfanta installed and working, however I am having difficulty in customising the layout. 我有Pagerfanta安装和工作,但我很难定制布局。 I read on Github that I need to pass through my_template , however I am unsure where this should be configured and what specificially this refers to. 我在Github上读到我需要通过my_template ,但是我不确定应该在哪里配置它以及具体指的是什么。

Custom template 自定义模板

If you want to use a custom template, add another argument 如果要使用自定义模板,请添加另一个参数

<div class="pagerfanta">
    {{ pagerfanta(my_pager, 'my_template') }}
</div>

Ideally I would like to have my own Twig template that I can modify, however I don't know if Pagerfanta supports this. 理想情况下,我想拥有自己可以修改的Twig模板,但我不知道Pagerfanta是否支持此模板。 Is it all done in PHP? 这一切都是用PHP完成的吗?

I don't think it supports Twig templates but for sure you can write your custom Template class to render the pagination however you want. 我不认为它支持Twig模板,但是你肯定可以编写自定义的Template类来呈现你想要的分页。

Let's say in your AppBundle, you will need to create MyCustomTemplate class which should extend Pagerfanta\\View\\Template\\DefaultTemplate : 假设你的AppBundle中需要创建MyCustomTemplate类,它应该扩展Pagerfanta \\ View \\ Template \\ DefaultTemplate

<?php

namespace Acme\AppBundle\Template;

use Pagerfanta\View\Template\DefaultTemplate;

class MyCustomTemplate extends DefaultTemplate
{
    // override whatever you need here ...
}

then register it in your services.yml file together with the view service: 然后将其与views服务一起注册到services.yml文件中:

services:
    acme_app.template.my_template:
        class: Acme\AppBundle\Template\MyCustomTemplate

    pagerfanta.view.my_template:
        class: Pagerfanta\View\DefaultView
        public: false
        arguments:
            - "@acme_app.template.my_template"
        tags: [{ name: pagerfanta.view, alias: my_template }]

then in your Twig templates you will be able to use: 然后在您的Twig模板中,您将能够使用:

{{ pagerfanta(my_pager, 'my_template') }}

which will result in displaying your custom pagination template. 这将导致显示您的自定义分页模板。

my_template is the alias of your view. my_template是视图的别名。 The next section in the Github link you have provided explains more. 您提供的Github链接的下一部分解释了更多内容。

It would look something like this 它看起来像这样

services:
    app.view.my_template:
        class: App\View\MyView
        public: false
        tags: [{ name: pagerfanta.view, alias: my_template }]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM