Customising the layout of Pagerfanta pagination with a custom template

可紊 提交于 2019-12-06 11:01:12

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.

Let's say in your AppBundle, you will need to create MyCustomTemplate class which should extend 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:

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:

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

which will result in displaying your custom pagination template.

my_template is the alias of your view. The next section in the Github link you have provided explains more.

It would look something like this

services:
    app.view.my_template:
        class: App\View\MyView
        public: false
        tags: [{ name: pagerfanta.view, alias: my_template }]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!