Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rhesa (5696)

rhesa
  (email not shown publicly)

Journal of rhesa (5696)

Sunday August 07, 2005
08:28 PM

Progress on HTML::Template::Plugin::Dot

[ #26169 ]

As you may know, Mark Stosberg and I are working on additions to HTML::Template. Mark has created HTML::Template::Pluggable, which adds a callback system to HTML::Template, similar to the successful one in CGI::Application. This will make creating plugins for HTML::Template a lot simpler.

He also started on HTML::Template::Plugin::Dot, which hooks into param to provide the magic-dot notation you might know from the Template Toolkit. I am currently enhancing that to allow mixing hashes and objects and more.

Here's an example script I have just written:

use HTML::Template::Pluggable;
use HTML::Template::Plugin::Dot;
use My::Feed;  # a Class::DBI object
 
my $t = HTML::Template::Pluggable->new( scalarref => \ q{
    Feed: <tmpl_var feed.name> at <tmpl_var feed.url>
    Items:<tmpl_loop items>
        "<tmpl_var item.title>" by <tmpl_var item.author> (<tmpl_var item.postdate.dmy>)</tmpl_loop>
    });
 
my $feed = My::Feed->retrieve(1);
$t->param( feed => $feed,
           items => [ map { {item => $_} } $feed->items ] );
 
print $t->output;

Sample output could look like this:

    Feed: Asynchrss at http://www.asynchrss.com
    Items:
        "News" by rhesa (21-10-2004)
        "More" by zsane (04-07-2005)

Hey, that's neat! Now, what if your web designer wants american style dates?

<tmpl_var item.postdate.mdy('/')>

Output:

    Feed: Asynchrss at http://www.asynchrss.com
    Items:
        "News" by rhesa (10/21/2004)
        "More" by zsane (07/04/2005)

And no changes to your code whatsoever! Now all you need to tell your designer is what objects he can expect, and what methods he can call. But you have that documented already, right? ;)

Obviously we're not intending to redo the Template Toolkit, but I think this feature is a great addition to HTML::Template, and a much-requested one at that. It's still fully backward-compatible too, so none of your existing code will break.

It should be on CPAN sometime soon, but you can get it from Marks public darcs repo now. I could definitely use some eyeballs on my code, as well as more tests. So get in touch if you're interested!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.