Ametad
Ametad

Reputation: 402

How to add pagination in a list on a frontend view?

In octoberCMS, how do I paginate a list with hundreds of items and display pagination elements?

Upvotes: 2

Views: 454

Answers (1)

Ametad
Ametad

Reputation: 402

In your component (this is like a controller) get all Users in chunks of 15 per page and pass them to your page view:

$users = User::paginate(15);
$this->page['users'] = $users;

In your view render a list and below the pagination-links (automatically!).

<div class="container">
    {% for user in users %}
        {{ user.name }}
    {% endfor %}
</div>

{{ users.render|raw }} // This renders pagination links

Upvotes: 3

Related Questions