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).


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?

- 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'


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


<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.


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