Yeah, I used to use TT, <a href="http://www.template-toolkit.org/">http://www.template-toolkit.org/</a>, and it worked
quite nice. It made it so much easier so I didn't have any HTML
code mixed in with my Perl. Now I am programming in ASP :/<br>
<br>
Randy<br><br><div><span class="gmail_quote">On 9/9/05, <b class="gmail_sendername">Mike South</b> <<a href="mailto:msouth@gmail.com">msouth@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
If you want something that can do everything HTML::Template does, but<br>also anything else you could possibly want, look at Template Toolkit.<br><br>I have used both fairly extensively, and sooner or later you are going<br>
to run into a limitation with HTML::Template that you can't easily get<br>around. Template Toolkit is very powerful and highly extensible and<br>is unlikely to ever run out of power for what you want to do.<br><br>If you're just starting fresh with a new project, I would recommend
<br>going with Template Toolkit from the beginning so that you don't end<br>up having to rewrite all your templates later when your application's<br>need move out beyond what HTML::Template can do.<br><br>Just to give you a couple of examples:
<br><br>In HTML::Template you can do a <tmpl_if foo>, but it only tells you if<br>foo is true or false. What if you want <tmpl_if foo='blah'>? What if<br>you later realize that everything would be much easier if you could do
<br><tmpl_if foo =~/bla(h|bber)/>? Template Toolkit can do an if with<br>equals or matches (not with the exact syntax I showed there, but it<br>can do it).<br><br>One of the nicest things about Template Toolkit is that you can pass
<br>in structured data and access it from the template. If you have an<br>array of hashes like this:<br><br>$folks = [<br>{<br>name => 'bob',<br>fruit =>'kiwi',<br>friends => [qw/ sally jessie raphael/],<br>},<br>
<br>{<br>name => 'sally',<br>fruit => 'kumquat',<br>friends =>[],<br>}<br>];<br><br>and you pass that in to a template as 'folks', you can have a loop like this:<br><br>[% FOREACH person = folks %]<br>[% <a href="http://person.name">
person.name</a> %] likes [% person.fruit %]<br>[% FOREACH friend = person.friends %]<br>[% IF loop.first %][% <a href="http://person.name">person.name</a> %] is a friend of: [%END%]<br>[% friend %]<br>[% END %]<br>[% END %]
<br><br>Here's a complete script. It's a little harder to get going with<br>Template Toolkit for the first time, but it's worth it.<br>#!/usr/bin/perl -w<br>use strict;<br>use Template;<br><br>my $folks = [<br> {<br> name => 'bob',
<br> fruit =>'kiwi',<br> friends => [qw/ sally jessie raphael/],<br> },<br> {<br> name => 'sally',<br> fruit => 'kumquat',<br> friends =>[],<br> },<br> {<br> name => 'misery',
<br> fruit => 'company',<br> friends =>[qw/ avarice sloth /],<br> },<br> {<br> name => 'batman',<br> fruit => 'robin',<br> friends =>[qw/ catwoman /],<br> },<br>];<br><br>
#and you pass that in to a template as 'folks', you can have a loop like this:<br><br>my $template = Template->new();<br><br>my $output;<br><br>$template->process(\*DATA, {folks=>$folks}, \$output) || die $template->error;
<br><br>print $output;<br><br>__DATA__<br>[%- FOREACH person = folks %]<br>======================<br><br> [%- <a href="http://person.name">person.name</a> %] likes [% person.fruit %]<br> [%- FOREACH friend = person.friends
-%]<br> [%- IF loop.first %]<br>[% <a href="http://person.name">person.name</a> %] is a friend of:[% END -%]<br>
[%- IF loop.last && person.friends.size > 1 %]
and[%<br>END %] [% friend %][% IF not loop.last and person.friends.size > 2<br>%],[% END -%]<br><br> [%- END -%]<br> [%- IF loop.last %]<br>======================<br> [%- END -%]<br><br>[%- END %]<br><br>HTML::Template is evolving, and I have done a lot of useful work with
<br>it, I'm not trying to dis it in the least. I just think it sounds<br>like you are already bumping around the edges of what it can do, and<br>you might be well advised to give Template Toolkit a try.<br><br>mike<br><br>
p.s. I also gzipped the file and attached it to avoid wrapping issues.<br> Here is what the output is supposed to look like:<br><br>[msouth@localhost ~]$ perl apm.pl<br><br>======================<br>bob likes kiwi<br>bob is a friend of: sally, jessie, and raphael
<br>======================<br>sally likes kumquat<br>======================<br>misery likes company<br>misery is a friend of: avarice and sloth<br>======================<br>batman likes robin<br>batman is a friend of: catwoman
<br>======================<br><br><br>On 9/9/05, Bill Raty <<a href="mailto:bill.raty@gmail.com">bill.raty@gmail.com</a>> wrote:<br>> I've found another interesting inflection point is the 'associate' parameter<br>
> given to the template constructor. Associate tells the template that<br>> another object has a 'param' method that acts like the one in CGI.pm: called<br>> with args its a setter, called without args in a list context returns a list
<br>> of parameter names that are provided by the object. Thus the code using the<br>> template can do some passive relection of templates by making a crafty<br>> 'param' method.<br>><br>> I'll send out examples if I'm able to cobble up anything promising.
<br>><br>> Meanwhile, thanks again Austin Mongers!<br>><br>> -Bill<br>><br>> On 9/8/05, Bill Raty <<a href="mailto:bill.raty@gmail.com">bill.raty@gmail.com</a>> wrote:<br>> > Thanks Wayne.<br>
> ><br>> > Aha! I may get away with it using the 'filters'. Also the special loop<br>> vars look promising:<br>> ><br>> ><br>> > <TMPL_LOOP NAME="FOO"><br>> > <TMPL_IF NAME="__first__">
<br>> > This only outputs on the first pass.<br>> > </TMPL_IF><br>> ><br>> > <TMPL_IF NAME="__odd__"><br>> ><br>> ><br>> > This outputs every other pass, on the odd passes.
<br>> > </TMPL_IF><br>> ><br>> > <TMPL_UNLESS NAME="__odd__"><br>> > This outputs every other pass, on the even passes.<br>> > </TMPL_IF><br>> ><br>> >
<br>> ><br>> > <TMPL_IF NAME="__inner__"><br>> > This outputs on passes that are neither first nor last.<br>> > </TMPL_IF><br>> ><br>> > This is pass number <TMPL_VAR NAME="__counter__">.
<br>> ><br>> ><br>> ><br>> > <TMPL_IF NAME="__last__"><br>> > This only outputs on the last pass.<br>> > <TMPL_IF><br>> ><br>> ><br>> > </TMPL_LOOP>
<br>> ><br>> > It still seems to require that the template writer to know too much about<br>> inclusions or adhere to a convention.<br>> ><br>> > -Bill<br>> ><br>> ><br>> ><br>
> ><br>> ><br>> ><br>> ><br>> ><br>> ><br>> > On 9/8/05, Wayne Walker <<a href="mailto:wwalker@bybent.com">wwalker@bybent.com</a> > wrote:<br>> > > You can do this with TMPL_IF and TMPL_INCLUDE
<br>> > > <head><br>> > > <tmpl_if name=calendar_present><br>> > > <tmpl_include name="path/to/cal.js"><br>> > > </tmpl_if><br>> > > </head>
<br>> > > <body><br>> > > stuff<br>> > > <tmpl_if name=calendar_present><br>> > > <div .....><br>> > > </tmpl_if><br>> > > </body>
<br>> > ><br>> > > This requires that you set calendar_present=1 in the calling program.<br>> > ><br>> > > Since I'm not sure what decides if the calendar ends up in the<br>> > > container, I can't guess further
<br>> > ><br>> > ><br>> > > On Thu, Sep 08, 2005 at 04:58:52PM -0500, Bill Raty wrote:<br>> > > ><br>> > > > I'm trying not to reinvent the wheel, but I'm having difficulty
<br>> determining<br>> > > > if the wheel I'm needing has been invented.<br>> > > ><br>> > > > I've looked at HTML::Template POD, and I get the basic concept. In<br>> my<br>
> > > > ignorance I'm failing to see how I can apply it to my problem, and<br>> ifthere<br>> > > > are other CPAN modules that are better suited to my task.<br>> > > ><br>> > > > I want to have a DWIMy page component system so that page controls
<br>> can be<br>> > > > called out and "Do The Right Thing". Example:<br>> > > ><br>>
> >
> I have a calendar input widget
set that<br>> requires pieces of HTML,<br>> > > > JavaScript, and CSS, which need to be exposed in the container<br>> page; a<br>> > > > script tag in the "head", a 'div' that needs to appear early on
<br>> inside the<br>> > > > "body" tag, and the 'input' tag that has event handlers that usethe<br>> earlier<br>> > > > script tag.<br>> > > > I'd like a system that abstract the container page, that lets me
<br>> develop the<br>> > > > calendar control component as if it were the containing page, but<br>> when<br>> > > > added/included/embedded in the container page the system smartly<br>> places the
<br>> > > > control component elements in the correct part of the containing<br>> page. The<br>> > > > clincher is the second add of the calendar widget doesn't duplicate<br>> the<br>> > > > 'script' and 'div' tags, but only interjects the 'input' tag for
<br>> the second<br>> > > > control.<br>> > ><br>> > > > _______________________________________________<br>> > > > Austin mailing list<br>> > > > <a href="mailto:Austin@pm.org">
Austin@pm.org</a><br>> > > > <a href="http://mail.pm.org/mailman/listinfo/austin">http://mail.pm.org/mailman/listinfo/austin</a><br>> > ><br>> > > --<br>> > ><br>> > > Wayne Walker
<br>> > ><br>>
> >
<a href="mailto:wwalker@bybent.com">wwalker@bybent.com</a> Do
you use Linux?!<br>> > >
<a href="http://www.bybent.com">http://www.bybent.com</a>
Get Counted!<br>> <a href="http://counter.li.org/">http://counter.li.org/</a><br>> > > Perl - <a href="http://www.perl.org/">http://www.perl.org/</a> Perl User Groups -<br>> <a href="http://www.pm.org/">
http://www.pm.org/</a><br>> > > Jabber: <a href="mailto:wwalker@jabber.gnumber.com">wwalker@jabber.gnumber.com</a> AIM: lwwalkerbybent<br>> > > IRC: wwalker on <a href="http://freenode.net">freenode.net
</a><br>> > > _______________________________________________<br>> > > Austin mailing list<br>> > > <a href="mailto:Austin@pm.org">Austin@pm.org</a><br>> > > <a href="http://mail.pm.org/mailman/listinfo/austin">
http://mail.pm.org/mailman/listinfo/austin</a><br>> > ><br>> ><br>> ><br>><br>><br>> _______________________________________________<br>> Austin mailing list<br>> <a href="mailto:Austin@pm.org">
Austin@pm.org</a><br>> <a href="http://mail.pm.org/mailman/listinfo/austin">http://mail.pm.org/mailman/listinfo/austin</a><br>><br>><br><br><br>_______________________________________________<br>Austin mailing list
<br><a href="mailto:Austin@pm.org">Austin@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/austin">http://mail.pm.org/mailman/listinfo/austin</a><br><br><br></blockquote></div><br>