mephisto next article link, and previous article link

Stamped: 2009-04-17 00:00:00 -0400 | Show comments

8.2 either removed the two functions I used to manage article navigation at the bottom (move your eyes dowwwwn just above the comments), or I added them and thought they came for free. After looking at the date in the master repo the latter appears to be true!

#article_drop.rb

## this goes in app/drops/article_drop.rb
def next?
  !@source.next.blank?
end

def previous?
  !@source.previous.blank?
end

Then to use it, go to your liquid template and add the following somewhere important:

#previous link
{% if article.previous? %}
  {{article | previous_article | link_to_article }}
{% else %}
  <a href="/">home</a>
{% endif %}

#next link
{% if article.next? %}
{{article | next_article | link_to_article }}
{% else %}
  <a href="/">home</a>
{% endif %}

If you want the links to have different text, say next/previous, you need to change the previous like so

#previous link
{% if article.previous? %}
  {{article | previous_article | link_to_article: 'PREVIOUS' }}
{% else %}
  <a href="/">home</a>
{% endif %}

#next link
{% if article.next? %}
{{article | next_article | link_to_article: 'NEXT' }}
{% else %}
  <a href="/">home</a>
{% endif %}

It would appear that the prev/next_article filters check to see if one exists, but I prefer to link back to home for usability purposes, and this lets me do that.

tags: mephisto
recent entries
Rails — A faster way for next and previous links on a post, article, or any model
The awkward things Siri says
Node.js — Getting oAuth Up and Running Using Express.js and Mongoose
Node.js — Getting oAuth Up and Running Using Express.js, Railway.js and Mongoose
Migrating from Rails 3.1 RC4 to RC5 using Heroku's Cedar Stack (also compass, unicorn, and sendgrid)
Random Freeze Fix for GTX 460 in 10.6 (osx86)
Wasted on Steam - an analytic tool for the Steam platform
Rails 3.1 — SQL logging to STDOUT during testing (with rspec, test::unit, or cucumber)
Rails 3.1 — Using ERB/HAML/etc within a Coffeescript JS file
Rails 3.1 — 'load_missing_contant': Expected ... to define ... (LoadError)
View the entire archive of articles