[Templates] Process, Loops and Scalar Reference output
Gavin Henry
ghenry@perl.me.uk
Sun, 22 Oct 2006 19:27:27 +0100 (BST)
<quote who="Andy Wardley">
> 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.
Ah, of course! I was looking in completely the wrong place. It's interated
over the whole file and needs to be reset.
>
> Try this instead:
>
> local $/ = undef; # slurp file in one go
>
> my $tt = Template->new( # define named template
> BLOCKS => {
> email => <DATA>,
> },
Didn't know you could do it this way either. Cheers.
> );
>
> $tt->process('email', ...etc...)
Many, many thanks!
Gavin.
>
>
> HTH
> A
>
> _______________________________________________
> templates mailing list
> templates@template-toolkit.org
> http://lists.template-toolkit.org/mailman/listinfo/templates
>