Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Template Toolkit 2

by lachoy (Parson)
on Apr 14, 2001 at 17:19 UTC ( [id://72573]=note: print w/replies, xml ) Need Help??


in reply to Template Toolkit 2

Just a couple little things. About caching: TT2 compiles a template to a Perl subroutine and caches it, which is very fast indeed! It also allows you to save this Perl subroutine to disk so the next time a system like mod_perl starts up you don't even have to parse the template. Sweet! (Yes, I'm a big fan of TT.)

Another nifty benefit that you touched on briefly is the consistent notation for variable access. For instance you can start out a template using a hash user:

my $tmpl = Template->new(); $tmpl->process( 'user_form.tmpl', { user => { name => 'Bruce Springsteen', last_login => '2000-01-01 05:45:00' }, common_date_format => \&my_date_format } );

user_form.tmpl

<p>Welcome [% user.name %]. Your last login was [% common_date_format( user.last_login ) %].</p>

Later, you might want to make user an object which has the methods name() and last_login():

my $user = User->fetch( 'theboss' ); my $tmpl = Template->new(); $tmpl->process( 'user_form.tmpl', { user => $user, common_date_format => \&my_date_format } );

This requires no modification to your template, which makes refactoring a larger system a more palatable task.

Chris
M-x auto-bs-mode

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://72573]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found