【问题标题】:Customising the layout of Pagerfanta pagination with a custom template使用自定义模板自定义 Pagerfanta 分页的布局
【发布时间】:2016-05-31 23:34:44
【问题描述】:

我已安装并运行 Pagerfanta,但是我在自定义布局时遇到了困难。我在Github 上读到我需要通过my_template,但是我不确定应该在哪里配置以及具体指的是什么。

自定义模板

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

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

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

【问题讨论】:

    标签: php symfony pagination twig pagerfanta


    【解决方案1】:

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

    假设在您的 AppBundle 中,您需要创建应扩展 Pagerfanta\View\Template\DefaultTemplate 的 MyCustomTemplate 类:

    <?php
    
    namespace Acme\AppBundle\Template;
    
    use Pagerfanta\View\Template\DefaultTemplate;
    
    class MyCustomTemplate extends DefaultTemplate
    {
        // override whatever you need here ...
    }
    

    然后将其与视图服务一起注册到您的 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 }]
    

    然后在您的 Twig 模板中,您将能够使用:

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

    这将导致显示您的自定义分页模板。

    【讨论】:

      【解决方案2】:

      my_template 是您的视图的别名。您提供的 Github 链接中的下一部分将解释更多信息。

      看起来像这样

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-04
        • 1970-01-01
        • 2012-10-16
        • 2016-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多