Hi Chris,
Now that Alexandro brings this up again, I have managed to add the
ability to truly render a partial inside a tag, model or anywhere else
you'd need to do it. It is, however, part of an extension with loads
of other stuff in it, and it requires some ugly hacks. Amongst other
things, Radiant has to be hacked to set the active controller, request
and response on tags.globals, so they are available to initialize an
ActiveView::Base instance to render a partial inside the tag.
If you are interested, I could provide the required code for in a
pastie, but you might want to stick with Alexandros solution which
seems less hacky, albeit not bullet proof. (How do you for instance
pass data to the partial with this approach?)
Cheers,
Casper Fabricius
On 17/01/2008, at 13:18, Alexandro Bernardi wrote:
> Chris Parrish wrote:
>> In an extension I'm working on, I'd like to define some medium to
>> large
>> blocks of dynamic html to be inserted via a single radius tag.
>> Because
>> this html isn't just a line or two and is tied to models and their
>> data,
>> I'd love to be able to create a true rails partial and tell the
>> snippet
>> to behave as a pseudo-controller and render the view in place of the
>> radius tag.
>>
>> I'm trying to keep a separation of concerns here and keep my code
>> clean
>> (and make use of all the html/erb sugar already built into rails).
>>
>> I don't suppose that there's any way to have a tag call
>> 'render :partial
>> => ...' much less get around the rails double-render when the
>> SiteController tries to render. Clever thoughts anyone?
>>
>> -Chris
>
> Hi Chris,
>
> I've a simple example how you can do this:
>
> Model:
>
> require 'radius'
> class Content < ActiveRecord::Base
> def body
> context = Radius::Context.new do |c|
> c.define_tag 'render' do |tag|
> content = "<!--partial-->[render]=" + tag.attr['partial'] +
> "<!--partial-->"
> end
> end
> parser = Radius::Parser.new(context, :tag_prefix => 'r')
> return parser.parse('<p>hello <r:render
> partial="partials/google_adsense" /></p>')
> end
> end
>
> View:
>
> <div class="body">
> <% @content.body.split("<!--partial-->").each do |body| %>
> <% if body.include?("[render]=") %>
> <%= render :partial=>body.split("[render]=")[1] %>
> <% else %>
> <%= markdown(body) %>
> <% end %>
> <% end %>
> </div>
>
>
> Maybe i could help you
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Radiant mailing list
> Post: [email protected]
> Search: http://radiantcms.org/mailing-list/search/
> Site: http://lists.radiantcms.org/mailman/listinfo/radiant
_______________________________________________
Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant