HTML::Template::Plugin::Dot - Add Magic Dot notation to HTML::Template
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
By adding support for this dot notation to HTML::Template, the programmers job of sending data to the template is easier, and designers have easier access to more data to display in the template, without learning any more tag syntax.
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 my_date.mdy('/') my_date.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.
TMPL_VARs inside of loops won't work unless a simple patch is applied to HTML::Template. We hope it will be updated with this patch soon.
http://rt.cpan.org/NoAuth/Bug.html?id=14037
Alternately, you can apply the patch to your own copy.
Patches, questions and feedback are welcome. This project is managed using the darcs source control system ( http://www.darcs.net/ ). My darcs archive is here: http://mark.stosberg.com/darcs_hive/ht-dot/
Mark Stosberg, c<< <mark@summersault.com> >> Rhesa Rozendaal, c<< <rhesa@cpan.org> >>
Parts copyright 2005 Mark Stosberg Parts copyright 2005 Rhesa Rozendaal
This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.
To install HTML::Template::Pluggable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Template::Pluggable
CPAN shell
perl -MCPAN -e shell install HTML::Template::Pluggable
For more information on module installation, please visit the detailed CPAN module installation guide.