[Analysis] Templates: The good, the bad, the ugly

Myk Melez myk at mozilla.org
Mon Dec 13 23:17:08 UTC 2004


J. Paul Reed wrote:

>Or, put another way: we could've used something lighter weight than
>Template Toolkit.
>  
>

Sure, but could we have used something better?  I don't think so.

>Templating engines that make you learn/use a new language (when the one you
>have is perfectly fine) are annoying. Use of a templating engine like TT in
>Perl is debatable; use of similar engines in PHP is completely asinine.
>  
>

We used to embed HTML in Perl, which no one still advocates, as far as I 
know.  The other two options are a specialized template language like TT 
and embedding Perl in HTML.  Are you suggesting that the latter approach 
would be better than TT's specialized language?

If so, note that TT supports doing so, and you can use TT to provide all 
the plumbing of templates (processing, libraries, variable management) 
without using any TT directives at all (except for the one to define a 
block of Perl code).

I wouldn't recommend this approach, however, primarily because TT's 
specialized language is much easier to use than pure Perl code for 
common template tasks, and learning it is simply not a significant 
burden compared to the increases in productivity and programming 
pleasure it provides.

>Also, there are some templates that use callbacks to call back into
>perl-code to do more work; when mail gets sent, this happens.
>
>It's ugly and should be replaced
>

This is actually the right thing to do in some cases, particularly when 
processing takes a while and we can give the user updates on its 
progress, f.e. when sending mail or modifying multiple bugs.  Of course, 
we would need iterative template output for that, but that can be hacked 
into TT2 and comes native in TT3, an alpha of which was recently released.

-myk




More information about the developers mailing list