Hi Drew,

> I'm the one who volunteered, and then I went on vacation for a 2 weeks.
> I have decided I will have a bare minimum draft done within a week. And
> then, as Matt suggested, people can just send
> suggestions/corrections/additions and the document will grow. When I
> have a draft, I'll post it to the list.

I'm new to this list, and I'd like to make a small contribution to the
HTML Template Comparison Sheet.

I've been using Text::Template for some time now, and I really enjoy using 
it because 1) it's fast, 2) it's small, just 28kb and 3) it uses Perl as
scripting language. 

>From the author's words:

 "When people make a template module like this one, they almost always
  start by inventing a special syntax for substitutions. For example, they
  build it so that a string like %%VAR%% is replaced with the value of
  $VAR. Then they realize the need extra formatting, so they put in some
  special syntax for formatting. Then they need a loop, so they invent a
  loop syntax. Pretty soon they have a new little template language."

 "This approach has two problems: First, their little language is
  crippled. If you need to do something the author hasn't thought of, you
  lose. Second: Who wants to learn another language? You already know
  Perl, so why not use it?"

That's a great concept. Anyway, I have tweaked the code a little, now
allows you to to make expressions like this one:

<? foreach $name (@names) { ?>

     Name: <?=$name?> <P>
     Job: <?=$job{$name}?> <P>
     <P>

<? } ?>

Notice the <?=$variable?> construction, It's the only "magic" that you 
have to know. If you already know Perl, the code is much cleaner than the 
HTML::Template counterpart, which would be something like this:

   <TMPL_LOOP NAME=EMPLOYEE_INFO>
         Name: <TMPL_VAR NAME=NAME> <P>
         Job: <TMPL_VAR NAME=JOB> <P>
        <P>
   </TMPL_LOOP>


Futhermore, with Text::Template you can access methods and modules
directly from the templates. For instance:

   <? my @emp = &main::sql("select name,job from employee"); ?>

   <? my @emp = $employee->list(); ?>


The only problem with Text::Template is that it fails on taint checks. 
However, because this module is very flexible, I believe that it's easy to
fix it by "untainting" the template before parsing it! 

If anyone is curious about the Text::Template module, take a look at the
author's homepage at: http://www.plover.com/~mjd/perl/

Best wishes,

Nelson

__________________________________________________________________
Nelson Ferraz                           Insite - Solucoes Internet
e-mail: [EMAIL PROTECTED]           http://www.insite.com.br/


Reply via email to