Keith Bingman wrote:

> Not as elegant as John's, but for some reason current.siblings  
> returns an empty array.

FWIW, the problem wasn't that current.siblings was returning null.  
Rather, the problem was that current.siblings returns a list that  
doesn't include the current page [1], so siblings.index(current) was  
returning null. Calling "self_and_siblings" instead of "siblings"  
works fine. Here's the corrected version:

class Behavior::Base

   define_tags do

     tag "next" do |tag|
       current = tag.locals.page
       by = tag.attr['by'] || 'title'
       siblings = current.self_and_siblings.sort_by { |page|  
page.attributes[by] }
       index = siblings.index(current)
       next_page = siblings[index + 1]
       if next_page
         tag.locals.page = next_page
         tag.expand
       end
     end

     tag "previous" do |tag|
       current = tag.locals.page
       by = tag.attr['by'] || 'title'
       siblings = current.self_and_siblings.sort_by { |page|  
page.attributes[by] }
       index = siblings.index(current)
       previous = siblings[index - 1]
       if previous
         tag.locals.page = previous
         tag.expand
       end
     end

   end

end

- Sean

[1] http://ar.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ 
ClassMethods.html

_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to