spsg has asked for the wisdom of the Perl Monks concerning the following question:

I'm new to Perl and to Template Toolkit, so please excuse me, but I really need some help.

I'm sending the request object in the handler, like this:

my $r = shift; my $request = Apache2::Request->new($r); my %vars = (request => $request,...); $TT->process($file_path, \%vars, $r) || return error($r,$TT->error( ))

And then, in the template, I do the following to access the request object:

[%RAWPERL%]my $request = $stash->get('request');[%END%]

I know it's working because I can get the parameters from the request object by doing this:

[%RAWPERL%] my $request = $stash->get('request'); my $param1 = $request->param('param1'); $output .= $param1; [%END%]

But I'm not sure if I'm doing this the right way, because I'm having some data inconsistency problems, and I'm trying to find out if the cause might be related to the way I'm accessing the request object.

I really would appreciate any help.

Replies are listed 'Best First'.
Re: Access Request Object from RAWPERL block in Template Toolkit template
by WizardOfUz (Friar) on Dec 15, 2009 at 16:02 UTC

    TT templates with RAWPERL blocks are a maintenance nightmare. Simply copy all the request parameters you need to your %vars hash and pass that to TT. This also gives you the chance to gracefully handle any exceptions raised by $request->param().

    Maybe your data inconsistency problems are a side effect of Apache2::Request's on-demand parsing strategy?

Re: Access Request Object from RAWPERL block in Template Toolkit template
by Anonymous Monk on Dec 15, 2009 at 14:58 UTC