ANN: HTML::Template::Pluggable and HTML::Template::Plugin::Dot preview
Mark Stosberg <mark-WmyhgDpj2fCHT8/[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.html-template |
|---|---|
| Message-ID | <[email protected]> |
Hello,
Template Toolkit's dot notation is almost ready for a CPAN release a
plugin for HTML::Template.
I would like to see HTML::Template support plugins directly, but I
intend to release HTML::Template::Pluggable as a sub-class so the
functionality can be publicly available until that time.
However, the dot notation still won't work inside of loops without a
trivial patch to HTML::Template to remove the hardcoding of the package
name in one place:
http://rt.cpan.org/NoAuth/Bug.html?id=14037
A preview release is here:
http://mark.stosberg.com/perl/HTML-Template-Pluggable-0.01.tar.gz
And some of the documentation is below.
Special thanks go to Rhesa Rozendaal for collaborating with me on this,
and to David Baker, Jason Crome and others for cheering us on.
Mark
SYNOPSIS
use HTML::Template::Pluggable;
use HTML::Template::Plugin::Dot;
my $t = HTML::Template::Pluggable->new(...);
Now you can use chained accessor calls and nested hashrefs as params,
and access them with a dot notation. You can even pass basic arguments
to the methods.
For example, in your code:
$t->param( my_complex_struct => $struct );
And then in your template you can reference specific values in the
structure:
my_complex_struct.key.obj.accessor('hash')
my_complex_struct.other_key
DESCRIPTION
By adding support for this dot notation to HTML::Template, the program-
mers job of sending data to the template is easier, and designers have
easier to access to more data to display in the template, without
learning any more tag syntax.
EXAMPLES
Class::DBI integration
Class::DBI accessors can be used in the template. If the accessor is
never called in the template, that data doesn't have to be loaded.
In the code:
$t->param ( my_row => $class_dbi_obj );
In the template:
my_row.last_name
DateTime integration
DateTime is a great date date formatting module. By using it with this
plugin, you can leave the date formatting in the template, where a
savvy designer can adjust it.
$t->param ( my_date => $dt_obj );
In the template:
my_row.strftime('%D');
Of course, if date formatting strings look scary to the designer, you
can keep them in the application, or even a database layer to insure
consistency in all presentations.
###########
Mark
--
http://mark.stosberg.com/
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf