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

由网友(姐旳素顏、秒殺妳旳浓妝)分享简介:I have Pagerfanta installed and working, however I am having difficulty in customising the layout. I read on Github that I need to pass through my_template, how...

I have Pagerfanta installed and working, however I am having difficulty in customising the layout. 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.

Custom template

VS自定义项目模板 自定义模板的分组

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. Is it all done in 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.

Let's say in your AppBundle, you will need to create MyCustomTemplate class which should extend PagerfantaViewTemplateDefaultTemplate:

<?php

namespace AcmeAppBundleTemplate;

use PagerfantaViewTemplateDefaultTemplate;

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: AcmeAppBundleTemplateMyCustomTemplate

    pagerfanta.view.my_template:
        class: PagerfantaViewDefaultView
        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.

阅读全文

相关推荐

最新文章