That pattern seems like a sufficiently good paradigm that some sort of convention should be created to do this. Perhaps

tag "my_tag" do |tag|
   @my_tag_data = MyModel.find_by_name(tag.attr['name'])
     tag.render
   end
 end



would automatically use view/tags/my_tag.haml.html or something similar.


On 21-Nov-08, at 1:45 PM, Chris Parrish wrote:

David, I still use that code in my extensions today (though I'd be interested to hear if anyone out there has come up with something better).

Now that Haml is built into Radiant, it would also be safe to convert to using that for your templates (it might be even easier to do the binding bit but I haven't tried yet).

-Chris

David Piehler wrote:
Chris Parrish's solution to rendering partials within a Radius tag works
great. It's been almost a year since he posted it though, and I was
wondering if this functionality should be done a different way now --
i.e. does Radiant has a built-in way to handle this now?

Thanks,
- Dave



Chris Parrish wrote:

[In the Model]

 tag "my_tag" do |tag|
   @my_tag_data = MyModel.find_by_name(tag.attr['name'])
     parse_template 'path_for/_my_template'
   end
 end

private

 def parse_template(filename)
   require 'erb'
   template = ''
File.open("#{MyExtensionNameExtension.root}/app/views/" + filename +
'.html.erb', 'r') { |f|
     template = f.read
   }
   ERB.new(template).result(binding)
 end


[In
/vendor/extensions/my_extension_name/app/views/path_for/ _my_template.html.erb]

<h1><%= @my_tag_data.name -%></h1>
<p>Value from my instance variable: <%= @my_tag_data.value -%></p>

This obviously isn't full-on rails parsing so it doesn't auto-mixin
helpers or anything fancy like that (I suppose I could require
ActiveView::Base or some such thing) but I didn't need that much capability.

-Chris


_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to