← Home

Ruby on Rails Plugin: WillPaginate Liquidized

This plugin allows you to use will_paginate with Liquid templates.

I originally wrote this for my Mephisto Paginated Article Lists plugin when Mephisto moved to will_paginate for pagination. But of course this is useful in any situation where you want to use will_paginate within Liquid templates, so I pulled it into a plugin of its own.

Currently there are two versions:

You can install them like this:

script/plugin install http://svn.artweb-design.de/stuff/rails/will_paginate_liquidized/tags/will_paginate_r413/
script/plugin install http://svn.artweb-design.de/stuff/rails/will_paginate_liquidized/tags/will_paginate_r436/

As for the newer version you can use it like follows.

Assign a will_paginate collection as a template variable as usual. Then, in your template, filter this collection through the will_paginate Liquid filter. E.g.:

@posts = Post.paginate :page => params[:page]
Liquid::Template.parse('').render({'posts' => @posts})

To specify a base path (or URL) for the links that are created, assign it to a will_paginate_options template variable, like so:

assigns = {'posts' => @posts, 'will_paginate_options' => {:path => '/posts'}

This is necessary because Liquid won't grant access to objects like the request object that ActionView templates have access to and that will_paginate relies on. So, we have to assign the path from the controller, which actually makes sense from a Liquid perspective.

Also, you can assign the usual will_paginate options this way. E.g. you can change the prev/next link texts using something like this:

'will_paginate_options' => {:prev_label => '← older posts'
                            :next_label => 'newer posts →' }

Please refer to the will_paginate documentation for a full list of options.