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::Seamstressmy $sth = $dbh->prepare($query); $sth->execute; $out = ''; foreach my $queryResult( $sth->fetchrow_hashref ) $out .= $mask->process( $queryResult ) } return $out;
To do the same in TT2, you create a template DB which uses Template::Plugin::DBI so you can write
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<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>
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
In reply to Re^4: RFC : Abstraction Markup
by Anonymous Monk
in thread RFC : Abstraction Markup
by simonodell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |