On Jan 7, 2008 4:16 PM, J Aaron Farr <[EMAIL PROTECTED]> wrote:

> One way I use the page_attachements extension is to create a single
> page under Root called Assets and then attach "global" files to this
> page.  I can then reference them directly by URL, but it would be nice
> to have a tag that allowed for referencing of attachments of other
> pages.
>

I did a quick hack patch to do something like this. BUt I discovered
page_attachment would also pick up images from parent pages. So adding all
the images to the home page is also an option.


$ diff -u page_attachment_tags.rb.orig page_attachment_tags.rb
--- page_attachment_tags.rb.orig        2007-12-26 21:49:41.234538413 +1300
+++ page_attachment_tags.rb     2007-12-26 22:20:39.262566335 +1300
@@ -86,6 +86,23 @@
     attributes = tag.attr.inject([]){ |a,(k,v)| a << %{#{k}="#{v}"}
}.join(" ").strip
     %{<img src="#{filename}" #{attributes + " " unless attributes.empty
?}/>}
   end
+
+  desc %{
+    Test
+
+    *Usage*:
+
+    <pre><code><r:attachment:global name="file.jpg"
[size="icon"]/></code></pre>
+  }
+  tag "attachment:global" do |tag|
+    page = tag.locals.page
+    attachment = PageAttachment.find_by_filename(tag.attr['name'])
+    size = tag.attr['size'] || nil
+    raise TagError, "attachment is not an image." unless
attachment.content_type.strip =~ /^image\//
+    filename = attachment.public_filename(size) rescue ""
+    attributes = tag.attr.inject([]){ |a,(k,v)| a << %{#{k}="#{v}"}
}.join(" ").strip
+    %{<img src="#{filename}" #{attributes + " " unless attributes.empty
?}/>}
+  end

   desc %{
     Renders a hyperlink to the attachment. The 'name' attribute is required
on this tag or the parent tag.
_______________________________________________
Radiant mailing list
Post:   Radiant@lists.radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to