cakephppaginationcakephp-4.x

How to create template for cakephp paginator?


I am trying to apply bootstrap 4 pagination style in cakephp paginator helper.

It is looking very hard to me.

This my simple html that I want to apply in paginator helper

<nav aria-label="Page navigation example">
  <ul class="pagination">
    <li class="page-item"><a class="page-link" href="#">Previous</a></li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item"><a class="page-link" href="#">Next</a></li>
  </ul>
</nav>

I created a paginator-templates file in config location.

config/paginator-templates.php

return [
    'number' => '<a href="{{url}}">{{text}}</a>',
];

Then I have initialized in appView.php

public function initialize(): void
{
       $this->loadHelper('Paginator', ['templates' => 'paginator-templates']);
}

After that getting below error

Config file "paginator-templates.php" did not return an array

How can I create a paginator-templates.php for apply bootstrap 4 pagination design in cakephp ? Has there any blog or example ?


Solution

  • What is the file returning?

    One way to work around this might be to use the setTemplate() method on the helper.

    https://book.cakephp.org/3/en/views/helpers/paginator.html#changing-templates-at-run-time

    Using your supplied example code I've been able to get the code working in Cake 3.8.5

    I wonder if you just forgot the opening <?php tag in your templates file so it's coming back as a string.