[Templates] Process, Loops and Scalar Reference output

Andy Wardley abw@wardley.org
Sun, 22 Oct 2006 11:30:17 +0100


Gavin Henry wrote:
>     $tt->process( \*DATA, $tt_vars, \$email_output )
>       || die $tt->error(), "\n";

Hi Gavin,

The problem is here.  The template is only available to be read
from the DATA handle the first time around the loop.  By the second
iteration, the DATA file pointer is already at the EOF and it
effectively looks like a zero-length template.

Try this instead:

     local $/ = undef;        # slurp file in one go

     my $tt = Template->new(  # define named template
         BLOCKS => {
             email => <DATA>,
         },
     );

     $tt->process('email', ...etc...)


HTH
A