On Dec 19, 2007 10:54 AM, Alex Teslik <alex@acatysmoof.com> wrote:
On Wed, 19 Dec 2007 14:02:59 +0100, Rhesa Rozendaal wrote
>
> There's a conflict between indenting your template for readability,
>  and the amount of whitespace that ends up in the output.
>

Very well put!

I beat this horse more deader a while back (and someone before me beat it dead
too):

http://www.mail-archive.com/html-template-users@lists.sourceforge.net/msg01959.html


It seems to me that the arguments in the conversation that links to are
pretty well put, too.  A simple filter added to the program does the trick:

     1  #!/usr/local/bin/perl
     2
     3  use strict;
     4  use warnings;
     5  use HTML::Template;
     6
     7  my $html_template_filter = sub {
     8      my $sref = shift;
     9      for( $$sref ) {
    10          s| <TMPL_LOOP (.*?)>\s* |<TMPL_LOOP $1>|gx;
    11          s| </TMPL_LOOP>\s*      |</TMPL_LOOP>|gx;
    12      }
    13  };
    14
    15  my @array = <DATA>;
    16  my $template = HTML::Template->new( arrayref => \@array,
    17      filter => $html_template_filter );
    18  $template->param( loop => [
    19      {line => "line1"},
    20      {line => "line2"},
    21      {line => "line3"},
    22      ] );
    23  my $stuff = $template->output;
    24  print $stuff;
    25
    26  __DATA__
    27  ##########################################
    28  <TMPL_LOOP name="loop">
    29  <TMPL_VAR name="line">
    30  </TMPL_LOOP>
    31  ##########################################

Output:

##########################################
line1
line2
line3
##########################################

(Assuming that's the trick I wanted.)  It's relatively easy for me to figure
out how to filter the template to produce the plain text I want.  Maybe
that's not so easy for a novice.  Maybe a cookbook for this sort of thing
could be helpful for novices and everyone else, too.  And/or as someone
mentioned, a library of common filters.

And while it's easy for me to figure this out, I have a hard time believing
that it would be easy for H::T to know exactly what I want.  But what if
there were a good mechanism for communicating that.  Wait, that
describes filters ...

Regards,

-- Brad