[Catalyst] Making pages within pages
Ash Berlin
ash at cpan.org
Tue Aug 1 11:08:12 CEST 2006
Paul Makepeace wrote:
> On 8/1/06, Ted Carnahan <ted at tedcarnahan.com> wrote:
>
>> Have a look at Catalyst::Plugin::SubRequest.
>>
>
> Ah, great, thanks, that looks like what my snippet was trying to achieve.
>
>
>> That will allow you to
>> make a completely separate request to a different action, and it returns
>> the finished result in a variable. Then it's up to you to write that
>> out to a file or do whatever with it. You can even do the subrequest
>> call from your TT view and skip the writing to disk entirely if it suits
>> you better.
>>
>
> What example would it be used from a view? At least for what I'm doing
> seems more like a controller activity.. Also, if I were trying to link
> to the generated page from the main result how could I not save it to
> disk? Aside from chicanery storing huge blobs in the session or
> whatever.
>
> Cheers, Paul
>
>
>> - Ted Carnahan
>>
>> On Tue, 2006-08-01 at 04:18 +0100, Paul Makepeace wrote:
>>
>>> I have an ordinary Cat app that needs to generate some subsidiary
>>> status output to a file that's then linked to in the main page's
>>> output. Originally I was going to do all the Template process etc
>>> myself but then wondered if there was a 'blessed' way of exploiting
>>> the catalyst machinery. Here's what I came up with,
>>>
>>> my ($self, $c) = @_;
>>> my $template = $c->stash->{template};
>>> $c->stash->{template} = 'news/subpage';
>>> $c->forward('View::TT');
>>> render_somewhere('news/status' => $c->response->out);
>>> $c->response->output(''); # so the view is re-rendered
>>> $c->stash->{template} = $template;
>>> $c->stash->{status_page} = 'news/status';
>>>
>>> What's nice about this is that news/subpage is found by catalyst - I'm
>>> wondering how much of render_somewhere() cat could help with. Doesn't
>>> have to follow that API, I just include that as an example; anything
>>> that gets the data down on disk will do.
>>>
>>>
>>>
>>> Paul
>>>
If you just want to render another template and don't want a full other
request (sub-requests behaves as if the user hit them in the browser)
look at
http://search.cpan.org/~sri/Catalyst-View-TT-0.23/lib/Catalyst/View/TT.pm#CAPTURING_TEMPLATE_OUTPUT
Ash
More information about the Catalyst
mailing list