A small plugin allowing you to use pagination from will_paginate inside your Liquor templates. This plugin is based on the plugin.
What do you need?
- Rails >= 2.2
- Liquor
- Will-Paginate >= 2.3.8 (as a gem or plugin)
rails plugin install git@github.com:tukan/will_paginate-liquorized.git
In your controller you might have something like this;
class MoviesController < ApplicationController # GET /movies # GET /movies.xml def index @movies = Movie.all.paginate(:page => params[:page], :per_page => 10) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @movies } end end end
In your view put something like this:
<%= Liquor::Template.parse("{{ movies | will_paginate_liquor }}").render({'movies' => @movies}, :registers => {:controller => @controller}) %>
NOTE: you must remember to pass the current controller in rendering (:registers). If anyone can think of a way around this let me know.
You won’t get any pagination links until you exceed 10 (per_page setting defined in controller action). You can also pass the following other optional arguments to the will_paginate_liquor method.
{{ movies | will_paginate_liquid : 'anchor', 'prev_label', 'next_label' }} anchor: apply a #anchor to all generated urls in the pagination prev_label: label for the previous page button next_label: label for the next page button
Registers a new filter tag for Liquid to access will_paginate using a custom LinkRenderer so it can reference the @controller from the current liquid context[:registers]. Uses ActionView::Helpers::UrlHelper, ActionView::Helpers::TagHelper for constructing the pagination links.
Who’s who?
- Modified by Timothy N. Tsvetkov from the Matthew Hutchinson original plugin.
- Authored by Matthew Hutchinson
- Modified from the original plugin at Artweb Design
- Will-Paginate by mislav
- Liquor by Timothy N. Tsvetkov and evilmartians
Right now this script is provided without warranty, or support from the author.
Will Paginate Liquorized by Matthew Hutchinson is licensed under a Creative Commons Attribution 2.0 UK: England & Wales License.