rikarsen's avatar

Custom pagination view

Hi. I want to change L5 pagination view. This is the pagination code:

{!! $categories->render() !!}

This is view:

<ul class="pagination">
    <li class="disabled"><span>«</span></li>
    <li class="active"><span>1</span></li>
    <li><a href="categories?page=2">2</a></li>
    <li><a href="categories?page=3">3</a></li>
    <li><a href="categories?page=2" rel="next">»</a></li>
</ul>

I want to add class .pull-right to pagination

<ul class="pagination pull-right">
    <li class="disabled"><span>«</span></li>
    <li class="active"><span>1</span></li>
    <li><a href="categories?page=2">2</a></li>
    <li><a href="categories?page=3">3</a></li>
    <li><a href="categories?page=2" rel="next">»</a></li>
</ul>

Who can help me?

0 likes
3 replies
RachidLaasri's avatar

How about adding the class using jQuery ?

$( "ul.pagination" ).addClass( "pull-right" );
willvincent's avatar

Changing things with jQuery should really be a last resort most of the time.

If you look at the code for the render method of the Paginate class, it allows for an alternate presenter. You best bet would probably be to create your own presenter, and alter the markup generated by it.

    /**
     * Render the paginator using the given presenter.
     *
     * @param  \Illuminate\Contracts\Pagination\Presenter|null  $presenter
     * @return string
     */
    public function render(Presenter $presenter = null)
    {
        $presenter = $presenter ?: new SimpleBootstrapThreePresenter($this);

        return $presenter->render();
    }

See: https://stackoverflow.com/a/28542607/1972101

JarekTkaczyk's avatar

@rikarsen Use custom presenter for the pagination:

// pass $presenter to the view
{!! $categories->render($presenter) !}}

And here's all you need:

<?php namespace Custom\Pagination;

use Illuminate\Pagination\BootstrapThreePresenter as BasePresenter;

class Presenter extends BasePresenter {

    /**
     * @inheritdoc
     */
    public function render()
    {
        if ($this->hasPages())
        {
            return sprintf(
                '<ul class="pagination pull-right">%s %s %s</ul>',
                $this->getPreviousButton(),
                $this->getLinks(),
                $this->getNextButton()
            );
        }

        return '';
    }
}

Please or to participate in this conversation.