I'm attempting to learn the Template Toolkit and I'm having trouble even getting started. Can anyone see what I'm doing wrong?
#!/usr/bin/perl
use strict;
use Template;
my $template = new Template;
my $file = 'tt/template.html';
my $data = {
env => \%ENV,
};
print "Content-type: text/html\n\n";
$template->process($file, $data) || die $template->error;
the template file:
<html>
<head>
</head>
<body>
<ul>
[% foreach thing in env.keys.sort %]
<li><b>{% thing %}:</b>[% env.thing %]</li>
[% end %]
</ul>
</body>
</html>
the output:
# perl template.pl
Content-type: text/html
file error - parse error - tt/template.html line 12: unexpected token
+(thing)
[% foreach thing in env.keys.sort %]
I even tried a
[% get env %]
at the top of my template and that didn't seem to do any good either.
Thanks.
AM
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.