Re: [nesta] Next & prev links
- From:
- Graham Ashton
- Date:
- 2011-04-12 @ 21:30
On 11 Apr 2011, at 15:50, Tommy Palmer <hi@tommyp.org> wrote:
> How would I go about creating next and previous links for articles based
on the date?
You'll need to write helper methods in your app.rb file that works out
what the next and previous articles are, and then add next/previous links
to your page template. You'll also need to copy the templates into a local
views folder so that you can edit them. See these docs:
http://nestacms.com/docs/design/editing-default-templates
To write the helper methods, have a look at the find_articles method on
the Page class:
https://github.com/gma/nesta/blob/master/lib/nesta/models.rb
It will return an array of page objects for every page on your site,
sorted by date. If you find the index of the current page in that array,
the next and previous will be easily available to you.
Make a couple of helper methods that use this sorted array to extract and
return the next/previous articles and you should be all set. Stick your
helpers in your app.rb file:
module Nesta
class App
helpers do
def next_article
# Ruby code here
end
def previous_article
# Ruby code here
end
end
end
end
Let us know how you get on — if you get it working it'd make a great guest
blog post! ;-)