Re: Nested templates

Brad Baxter <[email protected]> Mon, 30 Nov 2009 11:54:45 -0500
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
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 <[email protected]> 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 =3D 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 =3D 'blue';
>
> my $tmpl =3D HTML::Template->new(
> =A0 scalarref =A0 =A0 =A0 =A0 =3D> \$template,
> =A0 strict =A0 =A0 =A0 =A0 =A0 =A0=3D> 0,
> =A0 die_on_bad_params =3D> 0,
> =A0 case_sensitive =A0 =A0=3D> 1,
> );
>
> $tmpl->param(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 color =A0 =3D> $color,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 is_blue =3D> $color eq 'blue' ? 1 : 0,
> =A0 =A0 =A0 =A0 =A0 =A0);
>
> print $tmpl->output();
>
> So many advantages. The logic is completely separate from the presentatio=
n. If you send the template
> to a speaker of a different language, they can localize that with no prob=
lems. The code is much
> shorter at 29 lines vs. 42 lines, and its much more clear to a future mai=
ntainer 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