[Radiant] Access to request object from within tags (answer?)

Sean Cribbs seancribbs at gmail.com
Fri Jan 26 07:55:57 CST 2007


Kaleb,

Interesting technique.  I don't think you have to worry about it breaking
caching.  If your page/behavior is very dynamic, I would just make it
uncached.  Interestingly enough, in mental you have complete access to the
request and response variables because your tag definitions are defined
inside the Page model rather than in PageContext.

Sean

On 1/25/07, Kaleb Walton <kalebwalton at gmail.com> wrote:
>
> Well, I spoke 5 minutes too soon. I tried a few more things and found
> out how to get it to work - now this may be completely wrong on a
> number of levels but this got me the request within snippets that
> previously had a nil request.
>
> Does anyone know any ramifications of doing this? I haven't yet
> checked if it will break caching... we'll see about that.
>
> I notated the lines I changed or added with a <----
>
> In page_context.rb
>
>   def initialize(page, request)
>     super()
>
>     @page = page
>     globals.request = request <----
>     globals.page = @page
>
> ... ...
>
>   define_tag 'snippet' do |tag|
>     if name = tag.attr['name']
>       if snippet = Snippet.find_by_name(name.strip)
>         page = tag.locals.page
>         page.behavior.request = tag.globals.request <----
>         page.behavior.render_snippet(snippet)
>       else
>         raise TagError.new('snippet not found')
>       end
>     else
>       raise TagError.new("`snippet' tag must contain `name' attribute")
>     end
>   end
>
>
> behavior.rb
>
>   def lazy_initialize_parser_and_context
>     unless @context and @parser
>       @context = PageContext.new(@page, @request) <----
>       self.class.additional_tag_definition_blocks.each { |block|
> instance_eval &block }
>       add_tags_from_parent_to_context
>       @parser = Radius::Parser.new(@context, :tag_prefix => 'r')
>     end
>   end
> _______________________________________________
> Radiant mailing list
> Post:   Radiant at lists.radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.radiantcms.org/pipermail/radiant/attachments/20070126/a382b7fd/attachment.html


More information about the Radiant mailing list