html-template-users Mailing List for HTML::Template (Page 61)
Brought to you by:
samtregar
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(42) |
Jul
(80) |
Aug
(77) |
Sep
(97) |
Oct
(65) |
Nov
(80) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(63) |
Feb
(47) |
Mar
(45) |
Apr
(63) |
May
(67) |
Jun
(51) |
Jul
(78) |
Aug
(37) |
Sep
(45) |
Oct
(59) |
Nov
(50) |
Dec
(70) |
2004 |
Jan
(23) |
Feb
(90) |
Mar
(37) |
Apr
(53) |
May
(111) |
Jun
(71) |
Jul
(35) |
Aug
(58) |
Sep
(35) |
Oct
(35) |
Nov
(35) |
Dec
(20) |
2005 |
Jan
(51) |
Feb
(19) |
Mar
(20) |
Apr
(8) |
May
(26) |
Jun
(14) |
Jul
(49) |
Aug
(24) |
Sep
(20) |
Oct
(49) |
Nov
(17) |
Dec
(53) |
2006 |
Jan
(12) |
Feb
(26) |
Mar
(45) |
Apr
(19) |
May
(19) |
Jun
(13) |
Jul
(11) |
Aug
(9) |
Sep
(10) |
Oct
(16) |
Nov
(17) |
Dec
(13) |
2007 |
Jan
(9) |
Feb
(12) |
Mar
(28) |
Apr
(33) |
May
(12) |
Jun
(12) |
Jul
(19) |
Aug
(4) |
Sep
(4) |
Oct
(5) |
Nov
(5) |
Dec
(13) |
2008 |
Jan
(6) |
Feb
(7) |
Mar
(14) |
Apr
(16) |
May
(3) |
Jun
(1) |
Jul
(12) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(9) |
2009 |
Jan
(9) |
Feb
|
Mar
(10) |
Apr
(1) |
May
|
Jun
(6) |
Jul
(5) |
Aug
(3) |
Sep
(7) |
Oct
(1) |
Nov
(15) |
Dec
(1) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
|
Jun
|
Jul
(5) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
(3) |
Mar
|
Apr
(28) |
May
|
Jun
|
Jul
(3) |
Aug
(4) |
Sep
(3) |
Oct
|
Nov
(8) |
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(2) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
2016 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
From: Timm M. <tm...@ag...> - 2004-01-07 19:26:25
|
At 01:24 PM 1/7/04 -0500, Todd Chapman wrote: >I would like to pass a parameter to a template that >would be used to include another template. This >syntax does not seem to be valid: > > <TMPL_INCLUDE NAME="<TMPL_VAR NAME=include_param>"> > >How can I accomplish this? <> I use the output from one template to feed into another: ---- my $tmpl1 = HTML::Template->new( . . . ); my $tmpl2 = HTML::Template->new( . . . ); # Bunch of params() calls here $tmpl2->param( included => $tmpl1->output() ); print $tmpl1->output(); ---- With a <TMPL_VAR included> in $tmpl2's file. |
From: Todd C. <htm...@ch...> - 2004-01-07 19:16:06
|
I would like to pass a parameter to a template that would be used to include another template. This syntax does not seem to be valid: <TMPL_INCLUDE NAME="<TMPL_VAR NAME=include_param>"> How can I accomplish this? Thanks. -Todd |
From: Chris F. <cf...@do...> - 2004-01-07 18:09:22
|
> That would certainly work, though I would say this instead: > > &send_email( $email_message->output ); > > Since you're sending the e-mail to a controlled (& homogeneous) list of > HTML-receivable e-mail clients, you don't have to worry about a > corresponding text version. Thanks Jason, that is awesome... I never thought of passing "xxx->output" right to the mail sub.. That is perfect as now I can just do my standard my $template = new HTML::Template(filename => "filename"); Assign everything when and where I want to and output it to the send_mail sub - its perfection!! (thought I would have to do it via a FH before as the content wasn't being served up via http). Thanks for MIME::Lite suggestion, I know I'm going to have to use it someday when I need to send attachments - currently I use Mail::Sendmail and just bounce it off our SMTP server in the network - works great!. Thanks Again -Chris |
From: Jason P. <ja...@jo...> - 2004-01-07 16:32:34
|
Chris Faust wrote: > Looking at the docs - would the below work? > > my $email_message = HTML::Template->new( filehandle => *FH, > some_loop => \@someloop, > some_val => $someval, > some_if => 1, > ); > > &send_email($email_message); That would certainly work, though I would say this instead: &send_email( $email_message->output ); Since you're sending the e-mail to a controlled (& homogeneous) list of HTML-receivable e-mail clients, you don't have to worry about a corresponding text version. I like to use MIME::Lite to send e-mails. Off the top of my head (iow: not tested), the send_email func would look something like this: sub send_email { my ( $message, $mime ); ( $message ) = @_; $mime = MIME::Lite->new( To => 'dis...@yo...', From => 'mya...@yo...', Subject => 'Your Report', Data => $message ); $mime->send; # Exercise: Error Handling... } Jason |
From: Chris F. <cf...@do...> - 2004-01-07 16:17:06
|
Folks, HTML::Template has preformed above and beyond all my expectations when = it comes to serving user content from our site. I currently have a bunch of reporting that happens on a daily basis = which is mailed off to specific people in a HTML report. I'd like to take advantage of some of the HT features (like loops) to = create the emails instead of doing everything in perl and then simply = replacing it. Looking at the docs - would the below work? my $email_message =3D HTML::Template->new( filehandle =3D> *FH,=20 = some_loop =3D> \@someloop, = some_val =3D> $someval, = some_if =3D> 1, = ); = =20 &send_email($email_message); I know I should just try it and see what happens, but I also wanted to = see if anyone had a better suggestion on creating HTML emails. Thanks -Chris |
From: Mathew R. <mat...@re...> - 2004-01-01 23:07:41
|
Since you are stuffing the H::T loop with the dollar value for the = "current month" and "year-to-date" values, why not calculate the running = sub-total and stick that on the loop as well. Then in your template you = can, for example, use a <TMPL_IF EXPR=3D"__counter % 4">...</TMPL_IF> = syntax to display the sub-total at every 4th position. Having the sub-total available for each row allows the template file to = choose when it wants to display the sub-total. ----- Original Message -----=20 From: LDT=20 To: htm...@li...=20 Sent: Thursday, January 01, 2004 12:27 AM Subject: [htmltmpl] Can HTML::Template do subtotals? This is my first project using Perl and HTML::Template, and my first = posting to this users list (after searching = http://www.bluedot.net/mail/archive/ for things like "totals" and "total = row" and "subtotal"). =20 I'm trying to figure out how to insert subtotals periodically and to = calculate differences between two rows. For example, this is a mock up = similar to what I'm doing (mine is more complex): accounts curr month year-to-date 10-19 $xxx $xxx 20-29 $xxx $xxx 30-39 $xxx $xxx sub1 10-39 $xxxxx $xxxxx 40-49 $xxx $xxx 50-59 $xxx $xxx sub2 40-59 $xxxx $xxxx grand total $xxxxx $xxxxx diff b/w sub1 & sub 2 $xxx $xxx Right now, I'm using several case statements in my Sybase SQL and = several unions (which I know is pretty ugly)... but if I could get = HTML::Template and Perl to play nicely together and let me generate = occasional subtotals along the way (or differences as the case may be), = that would be great. Does HTML::Template have a way to do this? I have = the H:T documentation printed out (because I refer to it so often), and = I'm wondering if a TMPL_IF might be the answer. But, I can't wrap my = brain around how I could use it for subtotalling and differences. Oh, and feel free to dumb it down for me since I'm new to Perl, SQL, = [insert language here]. ;-) Thanks! Lori P.S. I didn't include my Perl code because I wasn't sure if it would = be necessary (and it's 600+ lines), but for the masochists among you, = you can see it here along with the .tmpl file: = http://www.perlmonks.org/index.pl?node_id=3D108949&user=3DLori713. The = .tmpl file is also included below: <!-- Begin Summary Report --> <TMPL_INCLUDE 'nc_start.tmpl'> <TMPL_INCLUDE 'nc_style.tmpl'> <TMPL_INCLUDE 'nc_titlebar.tmpl'> <TMPL_INCLUDE 'nc_rpt_hdr.tmpl'> <hr> <form name=3Dfrm_summ_rept method=3DPOST = action=3D"http://www.ncsu.edu"> <table border=3D1 cellspacing=3D0 cellpadding=3D1 width=3D"100%" = summary=3D"Column Headings and Data Cells"> <tr valign=3D"bottom"> <th width=3D"9%">Account Summary</th> <th width=3D"18%">Description</th> <th width=3D"4%">Current FTE</th> <th width=3D"9%">Current Budget</th> <th width=3D"9%">Current Month Activity</th> <th width=3D"9%">FYTD Activity</th> <th width=3D"9%">Pre-Encumbrances</th> <th width=3D"9%">Encumbrances</th> <th width=3D"11%">Budget Balance Available</th> <th width=3D"4%">Future FTE</th> <th width=3D"9%">Future Budget</th> </tr> <TMPL_LOOP NAME=3Dpassacts> <tr class=3D<TMPL_VAR NAME=3Dtrclass> bgcolor=3D<TMPL_VAR = NAME=3Dbgcolor>> <td align=3D"left" style=3D"cursor:pointer;cursor:hand;" onmouseover=3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <font color=3D#000000><TMPL_VAR = NAME=3Dcol_acct></td> <td align=3D"left" style=3D"cursor:pointer;cursor:hand;" title=3D"Account(s) <TMPL_VAR NAME=3Dcol_acct>"> <font color=3D#000000><TMPL_VAR = NAME=3Dcol_descr></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_cfte></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_cbud></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_cmo></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_fytd></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_pre></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_enc></td> <td align=3D"right"><TMPL_VAR NAME=3Dcol_bba></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_ffte></td> <td align=3D"right" style=3D"cursor:pointer;cursor:hand;"=20 title=3D"Click to drill down" onmouseover=3D"style.background=3D'#CCCCFF';"=20 onmouseout =3D"style.background=3D'<TMPL_VAR = NAME=3Dbgcolor>';"> <TMPL_VAR NAME=3Dcol_fbud></td> </tr> </TMPL_LOOP> </table> </form> <TMPL_INCLUDE 'nc_buttons.tmpl'> <TMPL_INCLUDE 'nc_end.tmpl'> <!-- End Summary Report --> -------------------------------------------------------------------------= ----- Do you Yahoo!? Yahoo! Photos - Get your photo on the big screen in Times Square |
From: Wayne W. <ww...@by...> - 2004-01-01 16:42:56
|
You could also look into Data::Grouper ! It was written specifically to support this kind of thing for HTML::Template :) On Wed, Dec 31, 2003 at 05:27:02AM -0800, LDT wrote: > > This is my first project using Perl and HTML::Template, and my first > posting to this users list (after searching > [1]http://www.bluedot.net/mail/archive/ for things like "totals" and > "total row" and "subtotal"). > > > > I'm trying to figure out how to insert subtotals periodically and to > calculate differences between two rows. For example, this is a mock > up similar to what I'm doing (mine is more complex): > > > > accounts curr month year-to-date > > 10-19 $xxx $xxx > > 20-29 $xxx $xxx > > 30-39 $xxx $xxx > > sub1 10-39 $xxxxx $xxxxx > > 40-49 $xxx $xxx > > 50-59 $xxx $xxx > > sub2 40-59 $xxxx $xxxx > > grand total $xxxxx $xxxxx > > diff b/w sub1 & sub 2 $xxx $xxx > > > > Right now, I'm using several case statements in my Sybase SQL and > several unions (which I know is pretty ugly)... but if I could get > HTML::Template and Perl to play nicely together and let me generate > occasional subtotals along the way (or differences as the case may > be), that would be great. Does HTML::Template have a way to do this? > I have the H:T documentation printed out (because I refer to it so > often), and I'm wondering if a TMPL_IF might be the answer. But, I > can't wrap my brain around how I could use it for subtotalling and > differences. > > > > Oh, and feel free to dumb it down for me since I'm new to Perl, SQL, > [insert language here]. ;-) > > > > Thanks! > > > > Lori > > > > P.S. I didn't include my Perl code because I wasn't sure if it > would be necessary (and it's 600+ lines), but for the masochists among > you, you can see it here along with the .tmpl file: > [2]http://www.perlmonks.org/index.pl?node_id=108949&user=Lori713. The > .tmpl file is also included below: > > > > <!-- Begin Summary Report --> > <TMPL_INCLUDE 'nc_start.tmpl'> > <TMPL_INCLUDE 'nc_style.tmpl'> > <TMPL_INCLUDE 'nc_titlebar.tmpl'> > <TMPL_INCLUDE 'nc_rpt_hdr.tmpl'> > <hr> > <form name=frm_summ_rept method=POST action="[3]http://www.ncsu.edu"> > <table border=1 cellspacing=0 cellpadding=1 width="100%" > summary="Column Headings and Data Cells"> > <tr valign="bottom"> > <th width="9%">Account Summary</th> > <th width="18%">Description</th> > <th width="4%">Current FTE</th> > <th width="9%">Current Budget</th> > <th width="9%">Current Month Activity</th> > <th width="9%">FYTD Activity</th> > <th width="9%">Pre-Encumbrances</th> > <th width="9%">Encumbrances</th> > <th width="11%">Budget Balance Available</th> > <th width="4%">Future FTE</th> > <th width="9%">Future Budget</th> > </tr> > > <TMPL_LOOP NAME=passacts> > <tr class=<TMPL_VAR NAME=trclass> bgcolor=<TMPL_VAR NAME=bgcolor>> > <td align="left" style="cursor:pointer;cursor:hand;" > onmouseover="style.background='<TMPL_VAR > NAME=bgcolor>';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <font color=#000000><TMPL_VAR > NAME=col_acct></td> > <td align="left" style="cursor:pointer;cursor:hand;" > title="Account(s) <TMPL_VAR NAME=col_acct>"> > <font color=#000000><TMPL_VAR > NAME=col_descr></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_cfte></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_cbud></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_cmo></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_fytd></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_pre></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_enc></td> > <td align="right"><TMPL_VAR NAME=col_bba></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_ffte></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_fbud></td> > </tr> > </TMPL_LOOP> > </table> > </form> > > <TMPL_INCLUDE 'nc_buttons.tmpl'> > <TMPL_INCLUDE 'nc_end.tmpl'> > <!-- End Summary Report --> > _________________________________________________________________ > > Do you Yahoo!? > Yahoo! Photos - [4]Get your photo on the big screen in Times Square > > References > > 1. http://www.bluedot.net/mail/archive/ > 2. http://www.perlmonks.org/index.pl?node_id=108949&user=Lori713 > 3. http://www.ncsu.edu/ > 4. http://us.rd.yahoo.com/evt=21486/*http://f1.pg.photos.yahoo.com/ph//spsimplenol?.file=ny_ts_splash.html -- Wayne Walker ww...@by... Do you use Linux?! http://www.bybent.com Get Counted! http://counter.li.org/ Perl - http://www.perl.org/ Perl User Groups - http://www.pm.org/ Jabber IM: ww...@ja... AIM: lwwalkerbybent |
From: Timm M. <tm...@ag...> - 2003-12-31 14:06:04
|
HTML::Template doesn't like doing any sort of logic beyond simple if statements and loops. You can do it with HTML::Template::Expr, or (preferably) you can calculate the totals in Perl and fill in the template with those values. At 05:27 AM 12/31/03 -0800, LDT wrote: >This is my first project using Perl and HTML::Template, and my first >posting to this users list (after searching ><http://www.bluedot.net/mail/archive/>http://www.bluedot.net/mail/archive/ >for things like "totals" and "total row" and "subtotal"). > >I'm trying to figure out how to insert subtotals periodically and to >calculate differences between two rows. For example, this is a mock up >similar to what I'm doing (mine is more complex): > >accounts curr month year-to-date >10-19 $xxx $xxx >20-29 $xxx $xxx >30-39 $xxx $xxx >sub1 10-39 $xxxxx $xxxxx >40-49 $xxx $xxx >50-59 $xxx $xxx >sub2 40-59 $xxxx $xxxx >grand total $xxxxx $xxxxx >diff b/w sub1 & sub 2 $xxx $xxx > >Right now, I'm using several case statements in my Sybase SQL and several >unions (which I know is pretty ugly)... but if I could get HTML::Template >and Perl to play nicely together and let me generate occasional subtotals >along the way (or differences as the case may be), that would be >great. Does HTML::Template have a way to do this? I have the H:T >documentation printed out (because I refer to it so often), and I'm >wondering if a TMPL_IF might be the answer. But, I can't wrap my brain >around how I could use it for subtotalling and differences. > >Oh, and feel free to dumb it down for me since I'm new to Perl, SQL, >[insert language here]. ;-) > >Thanks! > >Lori > >P.S. I didn't include my Perl code because I wasn't sure if it would be >necessary (and it's 600+ lines), but for the masochists among you, you can >see it here along with the .tmpl >file: ><http://www.perlmonks.org/index.pl?node_id=108949&user=Lori713>http://www.perlmonks.org/index.pl?node_id=108949&user=Lori713. >The .tmpl file is also included below: > ><!-- Begin Summary Report --> ><TMPL_INCLUDE 'nc_start.tmpl'> ><TMPL_INCLUDE 'nc_style.tmpl'> ><TMPL_INCLUDE 'nc_titlebar.tmpl'> ><TMPL_INCLUDE 'nc_rpt_hdr.tmpl'> ><hr> ><form name=frm_summ_rept method=POST >action="<http://www.ncsu.edu>http://www.ncsu.edu"> ><table border=1 cellspacing=0 cellpadding=1 width="100%" summary="Column >Headings and Data Cells"> ><tr valign="bottom"> ><th width="9%">Account Summary</th> ><th width="18%">Description</th> ><th width="4%">Current FTE</th> ><th width="9%">Current Budget</th> ><th width="9%">Current Month Activity</th> ><th width="9%">FYTD Activity</th> ><th width="9%">Pre-Encumbrances</th> ><th width="9%">Encumbrances</th> ><th width="11%">Budget Balance Available</th> ><th width="4%">Future FTE</th> ><th width="9%">Future Budget</th> ></tr> ><TMPL_LOOP NAME=passacts> > <tr class=<TMPL_VAR NAME=trclass> bgcolor=<TMPL_VAR NAME=bgcolor>> > <td align="left" style="cursor:pointer;cursor:hand;" > onmouseover="style.background='<TMPL_VAR > NAME=bgcolor>';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <font color=#000000><TMPL_VAR NAME=col_acct></td> > <td align="left" style="cursor:pointer;cursor:hand;" > title="Account(s) <TMPL_VAR NAME=col_acct>"> > <font color=#000000><TMPL_VAR NAME=col_descr></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_cfte></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_cbud></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_cmo></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_fytd></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_pre></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_enc></td> > <td align="right"><TMPL_VAR NAME=col_bba></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_ffte></td> > <td align="right" style="cursor:pointer;cursor:hand;" > title="Click to drill down" > onmouseover="style.background='#CCCCFF';" > onmouseout ="style.background='<TMPL_VAR > NAME=bgcolor>';"> > <TMPL_VAR NAME=col_fbud></td> > </tr> ></TMPL_LOOP> ></table> ></form> ><TMPL_INCLUDE 'nc_buttons.tmpl'> ><TMPL_INCLUDE 'nc_end.tmpl'> ><!-- End Summary Report --> > > >Do you Yahoo!? >Yahoo! Photos - ><http://us.rd.yahoo.com/evt=21486/*http://f1.pg.photos.yahoo.com/ph//spsimplenol?.file=ny_ts_splash.html>Get >your photo on the big screen in Times Square |
From: LDT <per...@ya...> - 2003-12-31 13:27:08
|
This is my first project using Perl and HTML::Template, and my first posting to this users list (after searching http://www.bluedot.net/mail/archive/ for things like "totals" and "total row" and "subtotal"). I'm trying to figure out how to insert subtotals periodically and to calculate differences between two rows. For example, this is a mock up similar to what I'm doing (mine is more complex): accounts curr month year-to-date 10-19 $xxx $xxx 20-29 $xxx $xxx 30-39 $xxx $xxx sub1 10-39 $xxxxx $xxxxx 40-49 $xxx $xxx 50-59 $xxx $xxx sub2 40-59 $xxxx $xxxx grand total $xxxxx $xxxxx diff b/w sub1 & sub 2 $xxx $xxx Right now, I'm using several case statements in my Sybase SQL and several unions (which I know is pretty ugly)... but if I could get HTML::Template and Perl to play nicely together and let me generate occasional subtotals along the way (or differences as the case may be), that would be great. Does HTML::Template have a way to do this? I have the H:T documentation printed out (because I refer to it so often), and I'm wondering if a TMPL_IF might be the answer. But, I can't wrap my brain around how I could use it for subtotalling and differences. Oh, and feel free to dumb it down for me since I'm new to Perl, SQL, [insert language here]. ;-) Thanks! Lori P.S. I didn't include my Perl code because I wasn't sure if it would be necessary (and it's 600+ lines), but for the masochists among you, you can see it here along with the .tmpl file: http://www.perlmonks.org/index.pl?node_id=108949&user=Lori713. The .tmpl file is also included below: <!-- Begin Summary Report --> <TMPL_INCLUDE 'nc_start.tmpl'> <TMPL_INCLUDE 'nc_style.tmpl'> <TMPL_INCLUDE 'nc_titlebar.tmpl'> <TMPL_INCLUDE 'nc_rpt_hdr.tmpl'> <hr> <form name=frm_summ_rept method=POST action="http://www.ncsu.edu"> <table border=1 cellspacing=0 cellpadding=1 width="100%" summary="Column Headings and Data Cells"> <tr valign="bottom"> <th width="9%">Account Summary</th> <th width="18%">Description</th> <th width="4%">Current FTE</th> <th width="9%">Current Budget</th> <th width="9%">Current Month Activity</th> <th width="9%">FYTD Activity</th> <th width="9%">Pre-Encumbrances</th> <th width="9%">Encumbrances</th> <th width="11%">Budget Balance Available</th> <th width="4%">Future FTE</th> <th width="9%">Future Budget</th> </tr> <TMPL_LOOP NAME=passacts> <tr class=<TMPL_VAR NAME=trclass> bgcolor=<TMPL_VAR NAME=bgcolor>> <td align="left" style="cursor:pointer;cursor:hand;" onmouseover="style.background='<TMPL_VAR NAME=bgcolor>';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <font color=#000000><TMPL_VAR NAME=col_acct></td> <td align="left" style="cursor:pointer;cursor:hand;" title="Account(s) <TMPL_VAR NAME=col_acct>"> <font color=#000000><TMPL_VAR NAME=col_descr></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_cfte></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_cbud></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_cmo></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_fytd></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_pre></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_enc></td> <td align="right"><TMPL_VAR NAME=col_bba></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_ffte></td> <td align="right" style="cursor:pointer;cursor:hand;" title="Click to drill down" onmouseover="style.background='#CCCCFF';" onmouseout ="style.background='<TMPL_VAR NAME=bgcolor>';"> <TMPL_VAR NAME=col_fbud></td> </tr> </TMPL_LOOP> </table> </form> <TMPL_INCLUDE 'nc_buttons.tmpl'> <TMPL_INCLUDE 'nc_end.tmpl'> <!-- End Summary Report --> --------------------------------- Do you Yahoo!? Yahoo! Photos - Get your photo on the big screen in Times Square |
From: Gabor S. <ga...@pe...> - 2003-12-23 07:28:06
|
On Mon, 22 Dec 2003, Roger Burton West wrote: > On Mon, Dec 22, 2003 at 09:49:48AM -0200, Gabor Szabo wrote: > > >So far the only way I could think of is to go over these arrays and > >replace the scalar values with hash-refs: > > Correct. You can do this in a single pass, of course: > > $tmpl->param(items => [map{{item => $_}} @items] ); > thanks for your confirmation and suggestion. Gabor |
From: Roderick A. A. <raa...@ac...> - 2003-12-23 00:16:19
|
I'm trying to reduce the number of templates I'm using for a project but can't figure out a good way to do this given the constraints of appearance. The easy one has two different forms wrapped by the same overall web page. (In my last project (if you want to call it that) because of changing specs I ended up creating a whole pile of wrapper pages with different TMPL_INCLUDEs for each portion of the process.) This time I'd like to have one wrapper and use it for a signing form then a status form. I see the conditional constructs <TMPL_IF BOOL> Some text that is included only if BOOL is true <TMPL_ELSE> Some text that is included only if BOOL is false </TMPL_IF> and can use it for this simple project but wonder if there are other tricks I can use for more complex pages? (Like fixing up my last mess :-) Any pointers or suggestions? TIA, Rod -- "Open Source Software - You usually get more than you pay for..." "Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL" |
From: Roger B. W. <ro...@fi...> - 2003-12-22 09:13:27
|
On Mon, Dec 22, 2003 at 09:49:48AM -0200, Gabor Szabo wrote: >So far the only way I could think of is to go over these arrays and >replace the scalar values with hash-refs: Correct. You can do this in a single pass, of course: $tmpl->param(items => [map{{item => $_}} @items] ); (untested but ought to work) Roger |
From: Mathew R. <mat...@re...> - 2003-12-22 08:20:26
|
your suggested solution - is the correct solution cheers, Mathew ----- Original Message -----=20 From: "Gabor Szabo" <ga...@pe...> To: <htm...@li...> Sent: Monday, December 22, 2003 10:49 PM Subject: [htmltmpl] LOOP over array of scalar elements >=20 > It might be a very simple question but I could not find the answer so = far: >=20 > In a larger hash I have an array-ref with simple scalars in it >=20 > items =3D> [ > 'apple', > 'banana', > 'orange' > ] >=20 > I'd like to use this directly in a H:T with something like the > following but I don't know if it's possible ? >=20 > <TMPL_LOOP NAME=3D"items"> > <TMPL_VAR><br> > </TMPL_LOOP> >=20 >=20 >=20 > So far the only way I could think of is to go over these arrays and > replace the scalar values with hash-refs: >=20 >=20 > items =3D> [ > {item =3D> 'apple'}, > {item =3D> 'banana'}, > {item =3D> 'orange'} > ] >=20 > and then I use > <TMPL_LOOP NAME=3D"items"> > <TMPL_VAR NAME=3D"item"><br> > </TMPL_LOOP> >=20 >=20 > thanks > Gabor >=20 >=20 > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up for = IBM's > Free Linux Tutorials. Learn everything from the bash shell to sys = admin. > Click now! = http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Gabor S. <ga...@pe...> - 2003-12-22 07:49:35
|
It might be a very simple question but I could not find the answer so far: In a larger hash I have an array-ref with simple scalars in it items => [ 'apple', 'banana', 'orange' ] I'd like to use this directly in a H:T with something like the following but I don't know if it's possible ? <TMPL_LOOP NAME="items"> <TMPL_VAR><br> </TMPL_LOOP> So far the only way I could think of is to go over these arrays and replace the scalar values with hash-refs: items => [ {item => 'apple'}, {item => 'banana'}, {item => 'orange'} ] and then I use <TMPL_LOOP NAME="items"> <TMPL_VAR NAME="item"><br> </TMPL_LOOP> thanks Gabor |
From: <And...@t-...> - 2003-12-22 00:00:08
|
Ich werde ab 12.12.2003 nicht im B=FCro sein. Ich kehre zur=FCck am 12.01.2004. Sehr geehrte Damen und Herren, in der Zeit bis zum 12.1.2004 bin ich nicht im B=FCro erreichbar. Aus diesem Grund werde Ihre Nachricht erst nach meiner R=FCckkehr beant= worten k=F6nnen. In dringenden F=E4llen senden Sie bitte Ihre Nachricht erneut in Kopie = an: css...@t-... Freundliche Gr=FC=DFe Dipl.Ing. Andreas Jablonowski T-Systems CSS GmbH Leiter Web & Knowledge Management Solutions Hausadresse: Roermonder Str. 615, 52072 Aachen Postanschrift: Postfach 10 06 55, 52006 Aachen Telefon: (0241) 93 79-499 Telefax: (0241) 93 79-619 Mobiltelefon: (0171) 73 78 68 0 E-Mail: And...@t-... Internet: http://www.t-systems.de= |
From: Roger B. W. <ro...@fi...> - 2003-12-20 11:13:32
|
On Tue, Dec 09, 2003 at 03:29:55AM -0500, Brett Sanger wrote: >I can see how this is too involved for a handful of pages, but I don't >see it as "silly" for any site of size. The problem I have with it is that, when you add a page, you need to add both the file and the database entry. For the main site I administer with H::T, I use my Set extension and have a few lines at the top: <!-- tmpl_set name=title value=Personnel --> <!-- tmpl_set name=related0 value=/ --> <!-- tmpl_set name=related1 value=contact.html --> <!-- tmpl_include name=top.inc.tmpl> (actual page content here) <!-- tmpl_include name=bottom.inc.tmpl> The site-building script takes these, adds appropriate headers and <title> tags and so on, and (in a two-pass process) builds all the related-pages lists with full titles too. So if I change a page's title, or want to add or delete a related page, I just have one file to do it in. Everything about that page is in a single place. Roger |
From: Joel <htm...@jo...> - 2003-12-10 16:50:13
|
>At 05:55 PM 12/10/03 +1100, Mathew Robertson wrote: >> >>In a template you may do something like: >> >><TMPL_IF user> >> <TMPL_IF user.name> >> <TMPL_VAR user.name.first> <TMPL_VAR user.name.last> >> </TMPL_IF> >> <TMPL_IF user.address> >> <TMPL_VAR user.address.street> >> <TMPL_VAR user.address.town> >> </TMPL_IF> >></TMPL_IF> >> >> >>Normally your code would look something like: >> >>if (length $user->name->first or $user->name->last ) { >> $tmpl->param ('user' => 1); >> $tmpl->param ('user.name' => 1); >> $tmpl->param ('user.name.first' => $user->name->first ); >> $tmpl->param ('user.name.last' => $user->name->last ); >>} >>if (length $user->address->street or $user->address->town) { >> $tmpl->param ('user' => 1); >> $tmpl->param ('user.address' => 1); >> $tmpl->param ('user.address.street' => $user->address->street); >> $tmpl->param ('user.address.town' => $user->address->town); >>} >> >> >>With the 'structure_vars' support you can do this: >> >>$tmpl->param( 'user.name.first' = $user->name->first ); >>$tmpl->param( 'user.name.last' = $user->name->last ); >>$tmpl->param( 'user.address.street' = $user->address->street ); >>$tmpl->param( 'user.address.town' = $user->address->town ); > >Actually, you'd just do this: > >$tmpl->param( user => $user ); > >And H::T would take care of calling the necessary methods for you. This is an easy workaround with a lovely little recursive function to traverse your hashref structure. (This is a real example, try it for yourself. Although I admit that one line of it is questionable, but it needs to know if a reference is a scalar or a hash, otherwise errors abound.) test.pl -- The code ------------------- #!/usr/bin/perl -w use strict; use HTML::Template; my $user = {name => {first => 'John', last => 'Doe'}, address => {street => '123 Main St', city => 'Washington', state => 'DC'}}; my $tmpl = HTML::Template->new(filename => 'test.txt', die_on_bad_params => 0); $tmpl->param(user => 1); &populate($tmpl, $user, 'user'); print $tmpl->output(); 1; sub populate { my $tmpl = shift; my $struct = shift; my $curr = shift; foreach (keys %$struct) { $tmpl->param("$curr.$_" => 1); if ($struct->{$_} =~ 'HASH') { &populate($tmpl, $struct->{$_}, "$curr.$_"); } else { $tmpl->param("$curr.$_" => $struct->{$_}); } } } test.txt -- The Template ------------------------ <TMPL_IF user> <TMPL_IF user.name> FName: <TMPL_VAR user.name.first> Lname: <TMPL_VAR user.name.last> </TMPL_IF> <TMPL_IF user.address> Street: <TMPL_VAR user.address.street> City: <TMPL_VAR user.address.city> State: <TMPL_VAR user.address.state> </TMPL_IF> </TMPL_IF> And if I remember correctly, Perl would allow you to "add" your own function to do this in HTML::Template at runtime. Example: sub HTML::Template::foo { return "foobar\n"; } my $template = HTML::Template->new(filename => 'blah'); print $template->foo; So technically, you could add a new function HTML::Template::structure_param that would do all the ugliness when called with: (assuming $user is a hashref) $tmpl->structure_param(user => $user); I love Perl. --Joel |
From: Sam T. <sa...@tr...> - 2003-12-10 16:15:40
|
On Wed, 10 Dec 2003, Emanuele wrote: > Apache::Request has a param() method that behaves much like the one from > CGI.pm query object, so it should work... > But unfortunately the only 'associate' example showed in the H::T pod > uses (only) CGI, hence my question. That depends on how similar Apache::Request's param() is to CGI.pm. HTML::Template uses two calls - one with no args to get all param names and the second with one arg to get the value for a parameter. If both those work then everything should be peachy. > A more general question(s): how do you use H::T in mod_perl? I use CGI::Application, either through Apache::Registry or in a custom mod_perl handler depending on the situation. > If so, do you know/use any (simple) mod_perl framework which could be > considered the pure mod_perl counterpart of CGI::Application? Huh? CGI::Application works great in mod_perl! -sam |
From: Timm M. <tm...@ag...> - 2003-12-10 14:50:19
|
At 05:55 PM 12/10/03 +1100, Mathew Robertson wrote: ><> >In a template you may do something like: > ><TMPL_IF user> > <TMPL_IF user.name> > <TMPL_VAR user.name.first> <TMPL_VAR user.name.last> > </TMPL_IF> > <TMPL_IF user.address> > <TMPL_VAR user.address.street> > <TMPL_VAR user.address.town> > </TMPL_IF> ></TMPL_IF> > > >Normally your code would look something like: > >if (length $user->name->first or $user->name->last ) { > $tmpl->param ('user' => 1); > $tmpl->param ('user.name' => 1); > $tmpl->param ('user.name.first' => $user->name->first ); > $tmpl->param ('user.name.last' => $user->name->last ); >} >if (length $user->address->street or $user->address->town) { > $tmpl->param ('user' => 1); > $tmpl->param ('user.address' => 1); > $tmpl->param ('user.address.street' => $user->address->street); > $tmpl->param ('user.address.town' => $user->address->town); >} > > >With the 'structure_vars' support you can do this: > >$tmpl->param( 'user.name.first' = $user->name->first ); >$tmpl->param( 'user.name.last' = $user->name->last ); >$tmpl->param( 'user.address.street' = $user->address->street ); >$tmpl->param( 'user.address.town' = $user->address->town ); Actually, you'd just do this: $tmpl->param( user => $user ); And H::T would take care of calling the necessary methods for you. |
From: Paulsen, B. <BPa...@le...> - 2003-12-10 14:19:24
|
It should work. The only trick with the "param" function is that if it's called with no arguments, it should return all the params that it knows about. I've written quite a few modules that provide a param function and I then pass those to HTML::Template and they work perfectly. The way I use H::T in mod_perl is to just do CGI code through Apache::Registry. In other words, I do the following: my $cgi =3D new CGI; print $cgi->header; print $template->output; If you have something that will generate the headers for you, then feel free to use that. Personally, I like the Apache::Registry way of doing things as it's very easy to run the same script in a non-mod-perl space. That, in turn, makes it easy to debug scripts written by people who don't understand the nuances of mon-perl. -----Original Message----- =46rom: Emanuele [mailto:em...@li...]=20 Sent: Wednesday, December 10, 2003 6:56 AM To: htm...@li... Subject: [htmltmpl] H::T in mod_perl (probably FAQs) Just some dumb questions by a new HTML::Template-user-wannabe. 1. My goal is to use the 'associate' H::T option in a "pure" mod_perl application (i.e. no CGI code handled by Apache::Registry or Apache::PerlRun.) Does the following work=3F use Apache::Request; use HTML::Template; sub handler { my $r =3D Apache::Request->instance(shift); my $template =3D HTML::Template->new(filename =3D> 'template.tmpl', associate =3D> $r); # some other code } Apache::Request has a param() method that behaves much like the one from CGI.pm query object, so it should work... But unfortunately the only 'associate' example showed in the H::T pod uses (only) CGI, hence my question. 2. A more general question(s): how do you use H::T in mod_perl=3F Just CGI code through Apache::Registry or you write your own pure mod_perl(tm) handlers=3F If so, do you know/use any (simple) mod_perl framework which could be considered the pure mod_perl counterpart of CGI::Application=3F The only one =66ound so far by me is Apache::PageKit (which does a lot more than CGI::Application really). It seems good, but I'm always scared to find myself sooner or later trapped in a too restrictive environment when using such frameworks. What do you think about PageKit=3F Thanks a lot. Emanuele (Italy) ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's =46ree Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/=3Fad_id=1278&alloc_id371&op=CCk _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users ------------------------------------------------------------------------------ This message is intended only for the personal and confidential use of the = designated recipient(s) named above. If you are not the intended recipient o= =66= this message you are hereby notified that any review, dissemination, = distribution or copying of this message is strictly prohibited. This = communication is for information purposes only and should not be regarded as = an offer to sell or as a solicitation of an offer to buy any financial = product, an official confirmation of any transaction, or as an official = statement of Lehman Brothers. Email transmission cannot be guaranteed to be = secure or error-free. Therefore, we do not represent that this information i= s= complete or accurate and it should not be relied upon as such. All = information is subject to change without notice. |
From: Keith J. <kja...@ey...> - 2003-12-10 13:12:56
|
The idea of a filter module or library is a great idea. Here are a couple I use all the time. 1) Put a comment in the template that will not be displayed in the resulting page: s!<tmpl_comment>.*?</tmpl_comment>!!gs; 2) Translate the SSI "include virtual" into a template include: s/<!--\s*#include virtual="[\/]?(.+?)"\s*-->/ <TMPL_INCLUDE NAME="$1">/ig; -- Keith Jackson <kja...@ey...> |
From: Emanuele <em...@li...> - 2003-12-10 11:55:53
|
Just some dumb questions by a new HTML::Template-user-wannabe. 1. My goal is to use the 'associate' H::T option in a "pure" mod_perl application (i.e. no CGI code handled by Apache::Registry or Apache::PerlRun.) Does the following work? use Apache::Request; use HTML::Template; sub handler { my $r =3D Apache::Request->instance(shift); my $template =3D HTML::Template->new(filename =3D> 'template.tmpl', associate =3D> $r); # some other code } Apache::Request has a param() method that behaves much like the one from CGI.pm query object, so it should work... But unfortunately the only 'associate' example showed in the H::T pod uses (only) CGI, hence my question. 2. A more general question(s): how do you use H::T in mod_perl? Just CGI code through Apache::Registry or you write your own pure mod_perl(tm) handlers? If so, do you know/use any (simple) mod_perl framework which could be considered the pure mod_perl counterpart of CGI::Application? The only one found so far by me is Apache::PageKit (which does a lot more than CGI::Application really). It seems good, but I'm always scared to find myself sooner or later trapped in a too restrictive environment when using such frameworks. What do you think about PageKit? Thanks a lot. Emanuele (Italy) |
From: Roger B. W. <ro...@fi...> - 2003-12-10 09:46:15
|
On Wed, Dec 10, 2003 at 12:18:52PM +1100, Mathew Robertson wrote: >Is this implemented as a filter? In any case, I would be interested in having a look at how you did this. Very much like the param version just posted here. Insert tags of the form: <tmpl_set name=x value=y> with _no_ quoting around the x and y (this is a quick-and-dirty hack); each one will provide a value for a top-level parameter. You can't do anything about values within loops with this. package HTML::Template::Set; use HTML::Template; use base qw(HTML::Template); sub new { my %set_params; my $set_filter = sub { my $text_ref=shift; my $match='<(?:\!--\s*)?tmpl_set\s*name=(.*?)\s*value=(.*?)\s*(?:--)?>'; my @taglist=$$text_ref =~ m/$match/gi; while (@taglist) { my ($t,$v)=(shift @taglist,shift @taglist); $set_params{$t}=$v; } $$text_ref =~ s/$match/<tmpl_if name=never><tmpl_var name=$1><\/tmpl_if>/gi; }; my $proto = shift; my $class = ref($proto) || $proto; my $self=HTML::Template->new(filter => $set_filter, @_); bless ($self, $class); $self->param(%set_params); return $self; } 1; |
From: Mathew R. <mat...@re...> - 2003-12-10 06:56:10
|
> > > - dot syntax, eg 'user.name' > > > >Allowing dots in variable names seems harmless enough. > <snip> >=20 >=20 > The thing is, 'user.name' isn't a variable name in the traditional=20 > way. Rather, it's saying 'I want the attribute "name" for the = variable=20 > "user"', thus providing a more OO approach. >=20 > I imagine that this would be implemented by passing an object that = provides=20 > accessors for the fields that would show up in the template. For the=20 > example above: >=20 > package My::UserVar; > use base 'HTML::Template::Var'; # For example >=20 > sub new > { > my $class =3D shift; > my $in =3D shift || { }; > return unless ref($in) eq 'HASH'; > my $self =3D { map { $_ =3D> $in->{$_} || '' } qw( name addr city = state=20 > postal )}; > bless $self, $class; > } > sub name { $_->{name} } > sub addr { $_->{addr} } > sub city { $_->{city} } > sub state { $_->{state} } > sub postal { $_->{postal} } >=20 >=20 > package main; >=20 > # $tmpl defined elsewhere, holding an HTML::Template object > my $user =3D My::UserVar->new({ name =3D> 'foo', addr =3D> 'bar' }); > $tmpl->param( user =3D> $user ); I hadn't considered doing it this way, though the idea of using a OO = styled notation appeals to me. I was thinking along the lines of: In a template you may do something like: <TMPL_IF user> <TMPL_IF user.name> <TMPL_VAR user.name.first> <TMPL_VAR user.name.last> </TMPL_IF> <TMPL_IF user.address> <TMPL_VAR user.address.street> <TMPL_VAR user.address.town> </TMPL_IF> </TMPL_IF> Normally your code would look something like: if (length $user->name->first or $user->name->last ) { $tmpl->param ('user' =3D> 1); $tmpl->param ('user.name' =3D> 1); $tmpl->param ('user.name.first' =3D> $user->name->first ); $tmpl->param ('user.name.last' =3D> $user->name->last ); } if (length $user->address->street or $user->address->town) { $tmpl->param ('user' =3D> 1); $tmpl->param ('user.address' =3D> 1); $tmpl->param ('user.address.street' =3D> $user->address->street); $tmpl->param ('user.address.town' =3D> $user->address->town); } With the 'structure_vars' support you can do this: $tmpl->param( 'user.name.first' =3D $user->name->first ); $tmpl->param( 'user.name.last' =3D $user->name->last ); $tmpl->param( 'user.address.street' =3D $user->address->street ); $tmpl->param( 'user.address.town' =3D $user->address->town ); regards, Mathew |
From: Karen J. C. <si...@ph...> - 2003-12-10 03:37:19
|
This is the sort of thing I was thinking of... it's quick and dirty (*very* dirty), and really not worth even making into a module, but I did, at least in theory (I haven't used it yet, and may never... I can't actually remember the circumstances in which I thought it might be useful). It stomps all over any ability to use caching and whatnot, but that's okay for me because anything that's using caching is already connected to the database server and wouldn't need this sort of storage. It also doesn't make use of my suggestion to keep it enclosed in comment boundaries, but it's really more of a "here's what I was talking about" sort of thing than a "this might be useful in this form" sort of thing. package HTML::Template::Config; use strict; use HTML::Template; sub new { # file my $class = shift; my $filename = ""; for (my $i = 0; $i <= $#_; $i += 2) { if (lc($_[$i]) eq "filename") { $filename = $_[$i+1]; splice @_, $i, 2; last; } } open FILE, $filename; my @template = <FILE>; close FILE; my $template_param; while ($template[0] =~ /^(\w+?)\=(.+)$/) { $template_param->{$1} = $2; shift @template; } return wantarray ? (HTML::Template->new(arrayref => \@template, @_), $template_param) : HTML::Template->new(arrayref => \@template, @_); } 1; Templates would go something like: fred=foo bar=baz <HTML><TMPL_VAR blah blah blah... -- Karen J. Cravens si...@ph... |