* Wayne Pascoe <[EMAIL PROTECTED]> [2002-04-18 07:36]:
> Hi all,
Hi, Wayne.
> I have a section of perl code that builds a hash from the results of a
> select on a database. This is as follows:
[-- snip --]
> Is there any way to do this in a template using Template::Toolkit ? If
> there is no way of doing this in Template::Toolkit, what is the right
> way of building the hash then ?
Of course there's a way to do it:
[% FOREACH id = SITE.keys %]
<li><a href="[% SITE.$id.URL %]">[% SITE.$id.CLIENT %]</a> - [% SITE.$id.YNUMBER
%] - [% SITE.$id.DATE %]</li>
[% END %]
They key is to use SITE.$id in the block.
You can also do:
[% FOREACH id = SITE.keys %]
[% import(SITE.$id) %]
<li><a href="[% URL %]">[% CLIENT %]</a> - [% YNUMBER %] - [% DATE %]</li>
[% END %]
Which is equivalent to:
for my $id (keys %{$SITE}) {
my $URL = $SITE->{$id}->{'URL'};
my $CLIENT = $SITE->{$id}->{'CLIENT'};
my $YNUMBER = $SITE->{$id}->{'YNUMBER'};
my $DATE = $SITE->{$id}->{'DATE'};
print qq(<li><a href="$URL">$CLIENT</a> - $YNUMBER - $DATE</li>\n);
}
Except you only have to do the last line. ;)
This assumes you call process as:
$t->process($file, { SITE => get_sitelist() })
(darren)
--
To do nothing is to be nothing.