Marc Logghe wrote:
-----Original Message-----
From: Xavier Robin [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 03, 2007 10:46 AM
To: catalyst@lists.rawmode.org
Subject: [Catalyst] Getting the result of the template processing

Hello all,

How to get the result of the processing of a template ?

I would like to do someting like that:

$c->stash->{template} = 'display.tt2';
my $result = $c->process_template;
# put $result in database

The processing of display.tt2 is quite long (a couple of seconds to go through nearly the whole database), so I would like to do it only once.

I'm using a TTSite view. I don't want to get the complete page, only the HTML code generated by the template. What command should I use in place of "$c->process_template"? I couldn't find any plugin to do that, but not sure I looked deeply enough to find it, though...

Hi Xavier,
I did something similar like you are trying to do. Only difference is
that the result was written to a file instead of being stored in a
database.
First you have to make sure that the output of your template is not
wrapped, because you are not interested in the complete HTML.
In order to achieve that, this thread might be of help:
http://thread.gmane.org/gmane.comp.web.catalyst.general/9823/

Second, to get your hands on the result after rendering you could do it
like this:

# only want the output from the template,
# no wrapping wanted
$c->stash->{nowrap} = 1;

$c->stash->{template} = 'display.tt2';
# force rendering
# by doing that, the body is set
$c->forward($c->view);
# get the rendered result from the body
my $result = $c->response->body;
# store $result in the database
# ...


No no no no - don't forward to the view and mess about with resetting stash params/body. Look at the docs on View::TT in the section about "CAPTURING TEMPLATE OUTPUT"

Ash

_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

Reply via email to