使用自定义模板自定义Pagerfanta分页的布局 [英] Customising the layout of Pagerfanta pagination with a custom template

查看:114
本文介绍了使用自定义模板自定义Pagerfanta分页的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装并可以使用Pagerfanta,但是在定制布局时遇到了困难.我在 Github 上阅读,我需要通过my_template,但是我不确定在哪里应该对其进行配置以及具体指的是什么.

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.

自定义模板

如果要使用自定义模板,请添加另一个参数

If you want to use a custom template, add another argument

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

理想情况下,我想拥有自己的可以修改的Twig模板,但是我不知道Pagerfanta是否支持此模板.这一切都是用PHP完成的吗?

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?

推荐答案

我不认为它支持Twig模板,但是可以肯定的是,您可以编写自定义的Template类以根据需要呈现分页.

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.

比方说,在您的AppBundle中,您将需要创建MyCustomTemplate类,该类应扩展

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 ...
}

然后将其与查看服务一起注册到您的services.yml文件中:

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 }]

然后可以在Twig模板中使用:

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.

这篇关于使用自定义模板自定义Pagerfanta分页的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆