From my understanding it boils down to
$DB->($query, $mask)
Where query is sql and mask is a template, and $DB is a function that basically does
my $sth = $dbh->prepare($query);
$sth->execute;
$out = '';
foreach my $queryResult( $sth->fetchrow_hashref )
$out .= $mask->process( $queryResult )
}
return $out;
Except he chose delimiters to be different and significant -- which is why he had to use regular expressions to parse his xml-ish balanced tags, instead of using XML::Twig or HTML::Seamstress
To do the same in TT2, you create a template DB which uses Template::Plugin::DBI so you can write
<table width="50%">
[% MACRO mask BLOCK %]
<tr>
<td>
[% news_title %]
</td>
<td>
[% news_headline %]
</td>
<td>[% WRAPPER link
action = "readnews"
newsitem = news_id %]Read More...[% END # block test %]
</td>
</tr>
[% END # macro block mask %]
[% INCLUDE DB ## db calls macro mask, can be redefined
query=' SELECT * FROM latestnews; '
%]
</table>
query is a variable, mask is macro ( a template ) , and the template DB calls the macro mask, after defining variables based on database column names (presumably news_id, news_title, news_headline ) to populate mask
This works out of the box with TT2.
Sure, you have to define the MACRO mask before INCLUDE-ing the template DB, but that could be remedied by expanding the syntax so you can assign macros to a variable, or it could be implemented as a Template::Plugin or Template::View -- not a lot of work
|