Yes, that solves a slightly different problem
than my (admittedly somewhat pointless) example,
but it doesn't address the nesting that I'm
after.  I don't do it a lot, but there are key
points where I want to, and I like to be able
to count on it working.  I'd like there to be
an option to new() that says, "Do repeated
substitutions until there aren't any more".

I suspect that would still incur a 'compile'
step each time, but I'd hope it could avoid
the copy from output() and the repeated param()
calls.

Thanks,

Brad


On Wed, Nov 25, 2009 at 10:58 AM, Alex Teslik <a...@acatysmoof.com> wrote:
> On Tue, 24 Nov 2009 21:24:30 -0500, Brad Baxter wrote
>>
>> Is there a better way?
>
> I would just do:
>
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
> use HTML::Template;
>
> my $template = qq|
> This is a <tmpl_var color> bird.
> This is a <tmpl_if is_blue>BLUE</tmpl_if> bird.
> This is a <tmpl_if is_blue>**BLUE**</tmpl_if> bird.
> |;
>
> # all the logic of what the color will be goes here
> my $color = 'blue';
>
> my $tmpl = HTML::Template->new(
>   scalarref         => \$template,
>   strict            => 0,
>   die_on_bad_params => 0,
>   case_sensitive    => 1,
> );
>
> $tmpl->param(
>               color   => $color,
>               is_blue => $color eq 'blue' ? 1 : 0,
>            );
>
> print $tmpl->output();
>
> So many advantages. The logic is completely separate from the presentation. 
> If you send the template
> to a speaker of a different language, they can localize that with no 
> problems. The code is much
> shorter at 29 lines vs. 42 lines, and its much more clear to a future 
> maintainer what is happening
> without any brain gymnastics.
>
> HTH,
> Alex
>



-- 
Brad Baxter
----------------------------------------------------------------------

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Html-template-users mailing list
Html-template-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to