Mephisto article list pagination plugin

posted: March 28th, 2007 · by: Sven

in: Programming · tagged as: , , , , , ·  6 comments »

When I switched to Mephisto last month I could not believe my eyes that there’s no post pagination on any of the section pages that list blog posts besides the archives.

Since, I wondered if that’s probably just a bit too closeminded to consider this a usability breakdown or something like this … might just be a matter of taste, too. But then I happened to run in this very issue twice the other day.

I consider this functionality crucial because it’s a well-known usability pattern all across the web these days. Millions of blogging engines do it this way (don’t they?), so it should be default in Mephisto, too, IMO … but actually it isn’t. So I decided to follow Rick’s suggestion and write a plugin to implement this.

Update: The following information is most probably outdated. Please refer to the Mephisto Plugin: Paged Article Lists project page.

Searching for advice on how to do this the right way in Ruby on Rails I’ve found a lot of interesting stuff … I just haven’t found anything about how to overwrite an existing applications controller action - something that I considered necessary for that pagination functionality I wanted to realize. If you happen to be able to tell me something about this, please do.

So here’s what I’ve been able to come up with myself.

I hook into the ActionController’s before_filter and overwrite the entire method from there! Uuuuuuuha. Yes, I consider this aproach to be rather brutally hackish and ugly. It actually disturbs me if I look at this! I just don’t know how to do it in a more apropriate way. Is there any?

([Update] I’ve found a less hackish way to overwrite the Controller in the meantime. I’ll put some notes together about some useful plugin dev techniques that I’ve collected.)

Here’s the code:

http://svn.artweb-design.de/stuff/mephisto/mephisto_paged_article_list

[Update] I’ve added some notes on how to use this plugin.

Leave a comment

6 Comments

  1. Scott said March 30th, 2007 at 05:59 PM  

    Any instructions on how to actually use the plugin? Are there any special liquid tags involved? Or is it just a matter of dropping it into a Mephisto install and it magically works?

  2. Sven said March 31st, 2007 at 12:16 AM  

    Whoops. Yes, sorry.

    I definitely should have described that. I’m away on holidays for some days but I’ll hand that in asap. As a quick shot, here’s a snippet copied from my themes/site-1/[theme-name]/templates/_shared.liquid

    
    {% if pages %}
        <p id="pagination">
            {{ section | prev_next_section_page_links: pages }}
        </p>
    {% endif %}
    

    This adds the pagination that you see (e.g.) on the blog homepage (http://www.artweb-design.de).

    HTH!

  3. Scott said March 31st, 2007 at 04:53 PM  

    Thanks Sven, much appreciated. I see mention of some form of pagination code in the changelog in Mephisto, but haven’t had any luck in getting it working. Hope to be able to use your plugin, at least in the meantime.

  4. Sven said April 3rd, 2007 at 01:34 AM  

    Scott,

    in case that you don’t have subscribe to my blog but the comments feed of this article: I’ve just added some notes on how to use this plugin

  5. Will Duncan said June 21st, 2007 at 01:27 PM  

    Since I came across this page first and did not have success with the code you posted in your comment, it rendered out a # instead of the older/newer post links. I’ll point out that this works in the _shared.liquid file

    {% if pages %}
        <p id="pagination">
            {{ section | prev_next_section_page_links: pages }}
        </p>
    {% endif %}

    Only difference is “page instead of pages…and since I am a lazy copy/paste freak I didn’t pick it up right away.

  6. Sven said June 26th, 2007 at 01:42 PM  

    Will, thanks for pointing that out! Year, I’ll correct that in my own comment (and when I’m at it I’ll add pre tags to your comment so that Markdown doesn’t screw your underscores … I’m getting to think that this behaviour is a major annoyance in Markdown actually).

Leave a comment

Name required
E-Mail and Website optional

If you can read this, you don't use a typical webbrowser that plays nice with CSS.
Please do not fill in anything here!

Hint: Markdown will be applied to your comment. If you post any code, be sure to escape underscores (like so: \_) if you do not want them to be converted to an <em>phasis.

artweb design
Sven Fuchs
Grünberger Str. 65
10245 Berlin, Germany


http://www.artweb-design.de

Fon +49 (30) 47 98 69 96
Fax +49 (30) 47 98 69 97