How do I use Codeigniter pagination inside Twig views? |
I am working on a online newspaper/blogging application with CodeIgniter 3.1.8 and Bootstrap 4. I have decided to add themes to it. The application is not HMVC, only MVC.
I thought it was a good idea to use the Twig template engine to the theme(s). For this purpose, I use CodeIgniter Simple and Secure Twig. The public views have the extension .twig, not .php. This part of the Posts controller is responsible with displaying the posts with pagination: PHP Code: private function _initPagination($path, $totalRows, $query_string_segment = 'page') { If I had classic codeigniter views, I would display the pagination on page this way (I already did, in a previous version of the project): PHP Code: <div class="pagination-container text-center"> But I now need a way to pass the pagination to Twig views. Adding the code above does not work, and I have not been able to find a viable alternative.
You can simply add that function as part of the data array that will be sent to the view in your controller, like so:
Code: $data['pagination'] = $this->pagination->create_links(); Then in your twig template, you echo the variable: Code: {{ pagination }} |
Welcome Guest, Not a member yet? Register Sign In |