[Radiant] Access to request object from within tags (answer?)
Kaleb Walton
kalebwalton at gmail.com
Fri Jan 26 08:11:37 CST 2007
I'm quite unfamiliar with Mental and only recently started working
with Radiant - I'll look into Mental to see if it meets my needs.
Thanks!
On 1/26/07, Sean Cribbs <seancribbs at gmail.com> wrote:
> 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
> >
>
>
> _______________________________________________
> Radiant mailing list
> Post: Radiant at lists.radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site:
> http://lists.radiantcms.org/mailman/listinfo/radiant
>
>
More information about the Radiant
mailing list