Hi all,
I have just started using the Template Toolkit on a recent web
application that I am developing. It's a fantastic tool! I wish I had
discovered it earlier. However, I have found a couple of issues which I'd
like to ask about:
1. Use of a FOREACH loop fails under WinNT using Perl 5.6.1
(ActiveState build 626). I have attached the template and a sample
script which run fine under Linux and Perl 5.004_01 but cause the
following error to occur under Win32 if DEBUG is enabled:
undef error - loop is undefined
If I change the template to use the shortened version of a FOREACH
(e.g. [% FOREACH userlist %], this script will work. However, the whole
reason I built this test script and template was because TT was causing
my Perl interpreter to crash when I tried to use it with my application. I
tried the shortened FOREACH in my app template but the interpreter
still crashed. I think this crash has something to do with the undef error
but could not find out any more information from the docs.
2. Installing the Template Toolkit under a version of Perl older than 5.005
which does not support the 'use base' pragma causes lots of error
messages when doing the make test. However, it seems to work still if I
do a make install. Is the 'use base' only part of the test suite and not
part of the actual files? Do I have a safe install or is this going to blow
up in my face eventually?
Thanks,
William
use Template;
## Output data via Template Toolkit
my $path = "./";
my $tmpl = "test.ttml";
my $tt = Template->new({
INCLUDE_PATH => $path,
DEBUG => '1',
});
# Process
$tt->process($tmpl, $data)
|| die "Error processing template: " . $tt->error . " [$!]";
[%- userlist = [
{ id => 'tom', name => 'Thomas' },
{ id => 'dick', name => 'Richard' },
{ id => 'larry', name => 'Lawrence' },
]
-%]
[%- FOREACH userlist -%]
[% id %] [% name %]
[% END -%]
[% FOREACH user = userlist %]
[% user.id %] [% user.name %]
[% END %]