[Radiant] Problem with tag.locals

Adam Salter adam at rokslide.com
Tue Apr 3 18:58:40 CDT 2007


Hey all,
I'm helping Andrea Franz work on his fantastic Gallery Extension:
http://darcs.bigchieflabs.com/radiant/extensions/gallery/
(download with 'darcs' - http://darcs.net)


Anyway I'm trying to add some globally available tags to it:

There is a Model declared thus:
class Gallery < ActiveRecord::Base
   has_many :items,
     :class_name => 'GalleryItem'
	<snip>
end

And I have made a module in the extension /lib called gallery_tags.rb  
which contains this (fake example)...

module GalleryTags
   #tags available globally, not just on GalleryPages
   include Radiant::Taggable

   tag "mytag" do |tag|
     if tag.attr["id"]
       tag.locals.gallery = Gallery.find_by_id tag.attr["id"]
     tag.expand
   end

   tag "anothertag" do |tag|
     tag.locals.gallery.name
   end

   <snip>
end

added to the extension with:
   def activate
     admin.tabs.add "Galleries", "/admin/gallery", :after =>  
"Layouts", :visibility => [:all]
     Page.send :include, GalleryTags
   end

yet when I do this in a page:

<r:mytag id='1'>
<r:anothertag>
</r:mytag>

I get this:
You have a nil object when you didn't expect it! The error occurred  
while evaluating nil.name


It seems that tag.locals.gallery is being set to nil in between the  
tag calls... I can't work out why because other extensions seem to do  
similar things... it's very confusing.

Any help much appreciated.

Thanks,
-Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.radiantcms.org/pipermail/radiant/attachments/20070404/a701cd40/attachment.html


More information about the Radiant mailing list