html-template-users Mailing List for HTML::Template (Page 101)
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: Sam T. <sa...@tr...> - 2002-08-14 18:17:33
|
Hello all. My first book, Writing Perl Modules for CPAN, was just released. This book was motivated largely by my experiences writing HTML::Template and running this mailing-list. I've had a great time writing modules for CPAN and I hope I can help others join the fun. If you're interested in finding out what I've been doing for the last year, instead of working on HTML::Template 3.0, this is your chance! Also, if you're not yet familiar with CGI::Application, the last chapter of the book is a complete introduction to a great module that supports HTML::Template. For more information, including a free download of the first chapter: http://apress.com/book/bookDisplay.html?bID=14 And to buy it at a reasonable price: http://www.amazon.com/exec/obidos/ASIN/159059018X/002-5718448-5632815 http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?isbn=159059018X Thanks, -sam |
From: Philip S T. <phi...@gm...> - 2002-08-14 13:59:30
|
Sometime on Aug 13, Fran Fabrizio assembled some asciibets to say: > <input type=text name=computer_1_name> > <input type=text name=computer_1_ip_address> > <input type=text name=computer_2_name> > <input type=text name=computer_2_ip_address> This is what I do, although I use it in a form to add authors to a publication. <tmpl_loop computers> <input type=text name="computer_<tmpl_var index>_name" value="<tmpl_var value>"> <tmpl_if error><span class="error><tmpl_var error></span> </tmpl_loop> This will not work with associate, but it's pretty simple to populate the template: my @computers; for(my $i=0; defined($cgi->param("computer_${i}_name")); $i++) { my %computer = ( index => $i, value => $cgi->param("computer_${i}_name"), error => check_param(...) ); push @computers, \%computer; } $template->param(computers => \@computers); -- It's hard to get ivory in Africa, but in Alabama the Tuscaloosa. -- Groucho Marx |
From: Sam T. <sa...@tr...> - 2002-08-14 06:25:10
|
On Tue, 13 Aug 2002, Kenny Smith wrote: > I just got this error, which seems to be intermitant... I'm using H::T 2.3, > apache 1.3.26, and mod_perl 1.27, anyone seen it before? > > HTML::Template::output() : Unknown item in parse_stack : at > .../HTML/Template.pm line 2503 This is an "impossible" error that should never occur. It checks that the object found on the stack is of a known type. Since _parse() only puts objects of known types onto the stack there's really no reason this error should be firing. What kind of options are you using to new()? It occurs to me that this might happen if you were using file_cache or shared_cache across versions of HTML::Template. Nothing else pops to mind though... Could you try the most recent version of HTML::Template and see if that helps? -sam |
From: Kenny S. <ke...@jo...> - 2002-08-14 05:34:46
|
Hi all, I just got this error, which seems to be intermitant... I'm using H::T 2.3, apache 1.3.26, and mod_perl 1.27, anyone seen it before? line 382 of show_journal.mod_perl is: $template->output(); ---------- error output --------- HTML::Template::output() : Unknown item in parse_stack : at .../HTML/Template.pm line 2503 HTML::Template::output('HTML::Template=HASH(0x12c24f0)') called at .../show_journal.mod_perl line 382 Apache::ROOTjournalscape_2ecom::Robert::_32002_2d08_2d13_2d22_3a14::__INDEX_ _::show_entry('Robert', 2002, 08, 13, 22, 14, 'HASH(0x12ecfb4)') called at .../show_journal.mod_perl line 51 Apache::ROOTjournalscape_2ecom::Robert::_32002_2d08_2d13_2d22_3a14::__INDEX_ _::main() called at .../show_journal.mod_perl line 25 Apache::ROOTjournalscape_2ecom::Robert::_32002_2d08_2d13_2d22_3a14::__INDEX_ _::handler('Apache=SCALAR(0x121a288)') called at .../Apache/Registry.pm line 149 eval {...} called at .../Apache/Registry.pm line 149 Apache::Registry::handler('Apache=SCALAR(0x121a288)') called at /dev/null line 0 eval {...} called at /dev/null line 0 Kenny Smith JournalScape.com |
From: Fran F. <fr...@mo...> - 2002-08-14 00:10:42
|
Ok, I'll try my best to give an accurate working example. Our application deals with tracking information about computers installed at various sites. One site may have many computers. We need to give the users the ability to edit all of the info about all of the computers at a particular site all at once in one form. So a form might look something like: <form...> <input type=text name=computer_1_name> <input type=text name=computer_1_ip_address> <input type=text name=computer_2_name> <input type=text name=computer_2_ip_address> <input type=submit> This way, they can edit both computers at this site at once and submit the changes. So far, so good. But this is hard-coded and doesn't scale at all for when we have 3 or 4 or 40 computers. So, we want to HTML::Template-ize this. So you might make a file called edit_computers.tmpl like this: <form...> <tmpl_loop computers> <input type=text name=computer_<tmpl_var computer_id>_name> <input type=text name=computer_<tmpl_var computer_id>_ip_address> </tmpl_loop> <input type=submit> Looks good. However, you want to do some error checking when they submit the form, say to check that the ip address they entered doesn't match the one for another computer at the same site. So, you write some server-side code to check for that in the database, and if it finds a duplicate, you want to alert the user and have him enter some other ip address. The nice thing to do is to show him the same form he had just filled in with the values he previously entered, with maybe some red text that says "Sorry, the IP address for Computer 2 is already assigned to another computer at this site." So I think, "hey, HTML::Template's associate feature comes in handy, I'll create a CGI object of the form, and hand that to the template to associate, so the form can fill itself back in and the user doesn't have to retype everything." You'll recall that associate simply takes every param() from the CGI and "publishes" it back to the template as tmpl_var's. So, in my example, I could do this: ... my $cgi = new CGI; my @params = $cgi->param(); my @errors; for my $param (@params) { if $param =~ /_ip_address/ and alreadyExistsInDb($cgi->param($param)) { push @errors, {error_text => "The IP address $cgi->param($param) is already assigned."}; } } if (length @errors > 0) { my $tmpl = new HTML::Template(filename => 'edit_computers.tmpl', associate => $cgi); $tmpl->param(errors => \@errors); print $cgi->header . $tmpl->output; return } # else go about your business So now you've managed in my example to set computer_1_name, computer_1_ip_address, computer_2_name, and computer_2_ip_address in your template. So far so good. The last thing remaining is to edit the template to fill in those form fields for you. So here you go: <tmpl_loop errors> <tmpl_loop error_text><br> </tmpl_loop> <form...> <tmpl_loop computers> <input type=text name=computer_<tmpl_var computer_id>_name value=<tmpl_var OOPS_CANT_DO_IT>> <input type=text name=computer_<tmpl_var computer_id>_ip_address value=<tmpl_var OOPS_CANT_DO_IT>> </tmpl_loop> <input type=submit> There's no way to get that value to be value=<tmpl_var computer_1_name> on the first pass and value=<tmpl_var computer_2_name> on the second, because that would require this: <input type=text name=computer_<tmpl_var computer_id>_name value=<tmpl_var computer_<tmpl_var computer_id>_name>> which doesn't work. Does everyone see my dilemma now? Thanks for being patient! =) -Fran At 04:06 PM 8/13/2002 -0700, Brian McCain wrote: >Without knowing how you're using the associate feature, it's hard to come up >with a workaround. It seems like loops should work for you, but if whatever >youre doing with associate is making that impossible, perhaps you could >include the portion of your code where you use associate? > >Brian > >----- Original Message ----- >From: "Fran Fabrizio" <fr...@mo...> >To: "Cory Trese" <ct...@on...> >Cc: <fr...@mo...>; "HTML::Template List" >Sent: Tuesday, August 13, 2002 3:24 PM Subject: RE: [htmltmpl] Dynamic >TMPL_VAR names? Is it possible? | | A loop does me no good. If I have two >sites, and I use a loop like | suggested, I get a form that looks >something like: | | | | | etc.... | | Two form fields in the same form >with the same name = broken form. | :-( Even worse, when I go to >repopulate the 'associate' feature | has I think now clobbered one of the >site_name values and both of | these form fields will get the same data in >the value= attribute. | :-( In general, yes, loops are the answer, but >when building forms | and/or trying to repopulate forms using the >'associate' feature of | H:T, loops don't work. | | I appreciate the quick >response though! Any other ideas? | | -Fran | | >You need a loop. See the >HTML::Template docs on LOOPS. | > | > | > | > >| > | > | > | > | >You pass a loop (AKA, "sites => >\@sites_array_of_hashref," ) with the | >necessary sites. This loop >construction is business-logic (we would | use a | >module that prepared >an array of hashrefs from a DBI routine.) | | | | | | | | | | | >------------------------------------------------------- | This sf.net >email is sponsored by: Dice - The leading online job board | for high-tech >professionals. Search and apply for tech jobs today! | >http://seeker.dice.com/seeker.epl?rel_code=31 | >_______________________________________________ | Html-template-users >mailing list | Htm...@li... | >https://lists.sourceforge.net/lists/listinfo/html-template-users | --- >Incoming mail is certified Virus Free. Checked by AVG anti-virus system >(http://www.grisoft.com). Version: 6.0.381 / Virus Database: 214 - Release >Date: 8/2/2002 |
From: Douglas K. <dlk...@rh...> - 2002-08-13 23:09:07
|
On Tuesday 13 August 2002 02:54 pm, Fran Fabrizio wrote: > Hello! =A0What I'm wondering is if this is possible: > > <input type=3Dtext > =A0 =A0 =A0 =A0 =A0name=3Dsite_<tmpl_var site_id>_name > =A0 =A0 =A0 =A0 =A0value=3D<tmpl_var site_<tmpl_var site_id>_name> > > > We're trying to use the 'associate' feature, but the form field names > need to be unique each time we load the form (because the form may > have site_12345_name and site_67890_name this field can't be just > site_name) and thus the value=3D has to be formed the way I'm trying > above, which breaks HTML::Template. =A0Is there another way to achieve > this? Why not build up both variables is the script? Then you would then endup= =20 with something like this. <input type=3Dtext name=3D<tmpl_var site_id_name> value=3D<tmpl_var site_value_id_name> > just my 2 cents. Douglas |
From: Brian M. <bm...@pa...> - 2002-08-13 23:06:16
|
Without knowing how you're using the associate feature, it's hard to come up with a workaround. It seems like loops should work for you, but if whatever youre doing with associate is making that impossible, perhaps you could include the portion of your code where you use associate? Brian ----- Original Message ----- From: "Fran Fabrizio" <fr...@mo...> To: "Cory Trese" <ct...@on...> Cc: <fr...@mo...>; "HTML::Template List" <htm...@li...> Sent: Tuesday, August 13, 2002 3:24 PM Subject: RE: [htmltmpl] Dynamic TMPL_VAR names? Is it possible? | | A loop does me no good. If I have two sites, and I use a loop like | suggested, I get a form that looks something like: | | <form blah...> | <input type=text name=site_name value="foo"> | <input type=text name=site_name value="bar"> | etc.... | | Two form fields in the same form with the same name = broken form. | :-( Even worse, when I go to repopulate the 'associate' feature | has I think now clobbered one of the site_name values and both of | these form fields will get the same data in the value= attribute. | :-( In general, yes, loops are the answer, but when building forms | and/or trying to repopulate forms using the 'associate' feature of | H:T, loops don't work. | | I appreciate the quick response though! Any other ideas? | | -Fran | | >You need a loop. See the HTML::Template docs on LOOPS. | > | ><tmpl_loop name="sites"> | > | ><tmpl_var name="site_id"><br> | ><a href="<tmpl_var name="site_url">"><tmpl_var name="site_name"></a> | > | ></tmpl_loop> | > | >You pass a loop (AKA, "sites => \@sites_array_of_hashref," ) with the | >necessary sites. This loop construction is business-logic (we would | use a | >module that prepared an array of hashrefs from a DBI routine.) | | | | | | | | | | | ------------------------------------------------------- | This sf.net email is sponsored by: Dice - The leading online job board | for high-tech professionals. Search and apply for tech jobs today! | http://seeker.dice.com/seeker.epl?rel_code=31 | _______________________________________________ | Html-template-users mailing list | Htm...@li... | https://lists.sourceforge.net/lists/listinfo/html-template-users | |
From: Fran F. <fr...@mo...> - 2002-08-13 22:33:01
|
A loop does me no good. If I have two sites, and I use a loop like suggested, I get a form that looks something like: <form blah...> <input type=text name=site_name value="foo"> <input type=text name=site_name value="bar"> etc.... Two form fields in the same form with the same name = broken form. :-( Even worse, when I go to repopulate the 'associate' feature has I think now clobbered one of the site_name values and both of these form fields will get the same data in the value= attribute. :-( In general, yes, loops are the answer, but when building forms and/or trying to repopulate forms using the 'associate' feature of H:T, loops don't work. I appreciate the quick response though! Any other ideas? -Fran >You need a loop. See the HTML::Template docs on LOOPS. > ><tmpl_loop name="sites"> > ><tmpl_var name="site_id"><br> ><a href="<tmpl_var name="site_url">"><tmpl_var name="site_name"></a> > ></tmpl_loop> > >You pass a loop (AKA, "sites => \@sites_array_of_hashref," ) with the >necessary sites. This loop construction is business-logic (we would use a >module that prepared an array of hashrefs from a DBI routine.) |
From: Cory T. <ct...@on...> - 2002-08-13 22:25:39
|
You need a loop. See the HTML::Template docs on LOOPS. <tmpl_loop name="sites"> <tmpl_var name="site_id"><br> <a href="<tmpl_var name="site_url">"><tmpl_var name="site_name"></a> </tmpl_loop> You pass a loop (AKA, "sites => \@sites_array_of_hashref," ) with the necessary sites. This loop construction is business-logic (we would use a module that prepared an array of hashrefs from a DBI routine.) > -----Original Message----- > From: htm...@li... > [mailto:htm...@li...]On Behalf Of > Fran Fabrizio > Sent: Tuesday, August 13, 2002 5:54 PM > To: HTML::Template List > Subject: [htmltmpl] Dynamic TMPL_VAR names? Is it possible? > > > > Hello! What I'm wondering is if this is possible: > > <input type=text > name=site_<tmpl_var site_id>_name > value=<tmpl_var site_<tmpl_var site_id>_name> > > > > We're trying to use the 'associate' feature, but the form field names > need to be unique each time we load the form (because the form may > have site_12345_name and site_67890_name this field can't be just > site_name) and thus the value= has to be formed the way I'm trying > above, which breaks HTML::Template. Is there another way to achieve > this? > > Thanks, > Fran > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: Dice - The leading online job board > for high-tech professionals. Search and apply for tech jobs today! > http://seeker.dice.com/seeker.epl?rel_code=31 > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Fran F. <fr...@mo...> - 2002-08-13 22:06:37
|
Hello! What I'm wondering is if this is possible: <input type=text name=site_<tmpl_var site_id>_name value=<tmpl_var site_<tmpl_var site_id>_name> > We're trying to use the 'associate' feature, but the form field names need to be unique each time we load the form (because the form may have site_12345_name and site_67890_name this field can't be just site_name) and thus the value= has to be formed the way I'm trying above, which breaks HTML::Template. Is there another way to achieve this? Thanks, Fran |
From: Philip S T. <phi...@gm...> - 2002-08-12 13:46:00
|
Sometime Today, Chan Wai Tik assembled some asciibets to say: > perl's variables and objects, especially their declaration and > convention. Would you give me some advice, please? read the perldata man page: man perldata it's all explained there very well. I cannot do a better job. > Also, I heard that using HTML::Template we could define a variable > and a counter in the template. Could you tell me how to use such > features, please? I am using HTML::Template version 2.5 . Thanks a I don't think this feature is in HTML::Template yet. -- Golly, I'd hate to have a kid like me! -- Calvin |
From: Chan W. T. <cs...@st...> - 2002-08-12 03:04:07
|
Hi Philip, Thank you very much for help. Your explaination is very clear. Since I am used to program in C++, I am quite confused about the usage of perl's variables and objects, especially their declaration and convention. Would you give me some advice, please? Also, I heard that using HTML::Template we could define a variable and a counter in the template. Could you tell me how to use such features, please? I am using HTML::Template version 2.5 . Thanks a lot. Yours, cwt > Sometime Today, Sam Tregar assembled some asciibets to say: > > > use HTML::Template; > > my $htmltemplate = HTML::Template->new("template.htm"); > > my %myHash; > > don't declare the hash here. > > > my @myRecord = []; > > This should either be: > > my @myRecord = (); > > OR: > > my $myRecord = []; > > read man perldata for the difference. > > > for(int $i=0; $i<3; $i++) > > { > > declare the hash here: > > my %myHash; > > > foreach my $obj($htmltemplate->query(loop=>"record")) > > { > > $myHash{$obj} = "Tom".$i; > > } > > push (@myRecord, %myHash); > > you cannot store hashes in arrays. man perldata for why. > > push @myRecord, \%myHash; > > > } > > $htmltemplate->param(record=>@myRecord); > > again, only use a scalar, so: > > ->param(record=>\@myRecord); > > > Philip > > PS: I had written a more elaborate mail, but it got lost accidentally, > so this one's probably a little short. You can search the archives for > the above, it's been asked before. > > > -- > Counting in octal is just like counting in decimal--if you don't use > your thumbs. > -- Tom Lehrer > > > |
From: Philip S T. <phi...@gm...> - 2002-08-11 13:27:19
|
Sometime Today, Sam Tregar assembled some asciibets to say: > use HTML::Template; > my $htmltemplate = HTML::Template->new("template.htm"); > my %myHash; don't declare the hash here. > my @myRecord = []; This should either be: my @myRecord = (); OR: my $myRecord = []; read man perldata for the difference. > for(int $i=0; $i<3; $i++) > { declare the hash here: my %myHash; > foreach my $obj($htmltemplate->query(loop=>"record")) > { > $myHash{$obj} = "Tom".$i; > } > push (@myRecord, %myHash); you cannot store hashes in arrays. man perldata for why. push @myRecord, \%myHash; > } > $htmltemplate->param(record=>@myRecord); again, only use a scalar, so: ->param(record=>\@myRecord); Philip PS: I had written a more elaborate mail, but it got lost accidentally, so this one's probably a little short. You can search the archives for the above, it's been asked before. -- Counting in octal is just like counting in decimal--if you don't use your thumbs. -- Tom Lehrer |
From: Philip S T. <phi...@gm...> - 2002-08-11 13:27:18
|
Sometime on Aug 10, Douglas Kirkland assembled some asciibets to say: > Try this. The %myHash needs to be a hard reference. I am not > totally sure why but it works. to answer why you'll need to read through man perldata. only scalars may be stored in an array or hash. -- Some people have no respect for age unless it's bottled. |
From: Douglas K. <dlk...@rh...> - 2002-08-11 05:44:45
|
On Sunday 11 August 2002 04:06 pm, Sam Tregar wrote: > for(int $i=0; $i<3; $i++) > { > foreach my $obj($htmltemplate->query(loop=>"record")) > { > $myHash{$obj} = "Tom".$i; > } > push (@myRecord, %myHash); push (@myRecord, \%myHash); > } > $htmltemplate->param(record=>@myRecord); > $htmltemplate->output(); Try this. The %myHash needs to be a hard reference. I am not totally sure why but it works. Douglas |
From: Sam T. <sa...@tr...> - 2002-08-10 23:10:25
|
---------- Forwarded message ---------- Date: Sat, 10 Aug 2002 20:45:49 +0800 From: cs_cwt <cs...@st...> To: sa...@tr... Subject: Help: HTML::Template Problem Dear Sam, I am a user of HTM::Template. I think HTML::Template is a great module, it completely divides the implementation of the front end and the back end. But I have a little problem when using it, would you mind to answer me my question, please? In my template, <html><body> <tmpl_loop record> <tmpl_var names> <tmpl_var ages> </tmpl_loop> </body></html> In my perl script, ... use HTML::Template; my $htmltemplate = HTML::Template->new("template.htm"); my %myHash; my @myRecord = []; for(int $i=0; $i<3; $i++) { foreach my $obj($htmltemplate->query(loop=>"record")) { $myHash{$obj} = "Tom".$i; } push (@myRecord, %myHash); } $htmltemplate->param(record=>@myRecord); $htmltemplate->output(); ... I got error from the above usage. It prompted me that it could not find the variable names. But if I change to the following ... use HTML::Template; my $htmltemplate = HTML::Template->new("template.htm"); my %myHash; my @myRecord = [{names=>"Tom0", age=>"Tom0}, {names=>"Tom1", age=>"Tom1}, {names=>"Tom2", age=>"Tom2} ]; $htmltemplate->param(record=>@myRecord); $htmltemplate->output(); ... The above did not prompt any error. Could you tell me the difference, please? Could you teach me how to insert data into HTML::Template's loop dynamically, please? Thanks a lot. cwt |
From: Philip S T. <phi...@gm...> - 2002-08-09 05:11:55
|
On Thu, 8 Aug 2002, Bill Moseley wrote: > haven't touched in over a year. What would be somewhat handy for both me > and the people editing the templates is if I could get HTML::Template to > prepend to a template a (HTML, in this case) comment saying the file name > of the template. Then a quick view/source in the browser would help us maybe this in the perl would work. print $cgi->header(); print "<!-- Template: $templatefilename -->\n"; print $template->output(); |
From: Cees H. <ce...@si...> - 2002-08-08 23:12:59
|
Quoting Bill Moseley <mo...@ha...>: > Hi, > > I'm working on a project with quite a few templates, and a project that I > haven't touched in over a year. What would be somewhat handy for both me > and the people editing the templates is if I could get HTML::Template to > prepend to a template a (HTML, in this case) comment saying the file name > of the template. Then a quick view/source in the browser would help us > know what template needs, eh, fixing. > > Any tricks to do this? I was trying to avoid adding a comment directly > into each of the templates as they may get moved around in the template > directory structure. What this really calls for is a __FILE__ special variable like perl has. It would be simple to add to HTML::Template, and could probably be turned on and off in the constructor. Then you could add <!-- Start File: <TMPL_VAR NAME="__FILE__"> --> Another simple way to do this is to use a filter. my $filename = 'template.tmpl' my $filter = sub { my $str_ref = shift; $$str_ref = "<!-- Start File: $filename -->".$$str_ref; return $str_ref; } my $template = HTML::Template->new(filename => $filename, filter => $filter, ); You could quite easily build your code so that this filter only gets applied if your script is in debug mode. Also, if you don't want to change any of your current code, you could create a subclass of HTML::Template that always applied this filter for you. If you look at the HTML::Template::Expr module, it inherits from HTML::Template, and then applies a default filter to all template files. You could use it as an example. Neither of these methods will work with TMPL_INCLUDE files. In order for that to work, the filter would have to be passed the name of the current file that is being filtered by the H:T module. Cees |
From: Bill M. <mo...@ha...> - 2002-08-08 20:00:26
|
Hi, I'm working on a project with quite a few templates, and a project that I haven't touched in over a year. What would be somewhat handy for both me and the people editing the templates is if I could get HTML::Template to prepend to a template a (HTML, in this case) comment saying the file name of the template. Then a quick view/source in the browser would help us know what template needs, eh, fixing. Any tricks to do this? I was trying to avoid adding a comment directly into each of the templates as they may get moved around in the template directory structure. Thanks, -- Bill Moseley mailto:mo...@ha... |
From: Chris D. <Chr...@Ma...> - 2002-08-08 09:50:54
|
A while ago I posted a solution that can defer the decision on the number of columns to the template designer. This may help. See http://bluedot.net/mail/archive/read.php?f=9&i=2353&t=2345 in the mailing list archive for details Chris -- Chris Davies, Manheim Online Tel. 0113 393-2004 Fax. 0870 444-0482. Mobile 07778 199069 -----Original Message----- From: htm...@li... [mailto:htm...@li...]On Behalf Of Roy Rubin Sent: Thursday, August 08, 2002 6:02 AM To: Philip S Tellis; HTML Template Subject: RE: [htmltmpl] H::T and Table Data > > I am writing a script that displays data in a 2-column format. > I am using > > HTML::Pager in order to only display a certain amount of > records per page. > > Given that, what is the best method to loop through the records and > > retrieve, essentially two records per HTML table row. > > I do this all the time. > > <tmpl_loop foo> > <tmpl_if __ODD__><tr></tmpl_if> > <td><tmpl_var foobar></td> > <tmpl_if __LAST__><tmpl_if > __ODD__><td> </td></tmpl_if></tmpl_if> > <tmpl_unless __ODD__></tr></tmpl_if> > </tmpl_loop> > > The first if __ODD__ checks if it's the start of a new row - 1, 3, 5, > etc. > The unless __ODD__ checks if it's the end of the row - after 2, 4, 6, > etc. > The if __LAST__ && __ODD__ checks if it is the last entry in the list, > but not an even entry, meaning there will be one blank entry in the > table. > > This will only work with two columns. More than that isn't possible. > > Philip > Thank you for the comments. I have spent the last few hours developing a solution that seems to work. In my case, it ended up being 4 columns across (4x2) - so I needed a flexible solution. Here it is (Any comments on how to improve it are always welcome): <snip> $sql = qq{SELECT Caption, Thumbnail, ID From News ORDER BY Position ASC}; $sth = $dbh->prepare($sql) or bail_out(); $sth->execute(); $rv = $sth->rows; $get_data_sub = sub { my ($offset, $rows) = @_; my @return_array; for (my $x = $offset; $x < $rows + $offset; $x=$x+4) { $newsql = $sql . " LIMIT $x, 4"; $sth = $dbh->prepare($newsql) or bail_out(); $sth->execute() or bail_out(); my @rv; while(($Caption, $Thumbnail, $ID) = $sth->fetchrow_array()){ push @rv, {Caption => $Caption, Thumbnail => $Thumbnail, ID => $ID}; } push @return_array, {NEWSITEM => \@rv}; } $sth->finish() or bail_out(); $dbh->disconnect() or bail_out(); return \@return_array; }; $pager = HTML::Pager->new( query => $co, get_data_callback => $get_data_sub, rows => $rv, page_size => 8, template => $template ); </snip> Roy ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Roy R. <ro...@ir...> - 2002-08-08 04:58:19
|
> > I am writing a script that displays data in a 2-column format. > I am using > > HTML::Pager in order to only display a certain amount of > records per page. > > Given that, what is the best method to loop through the records and > > retrieve, essentially two records per HTML table row. > > I do this all the time. > > <tmpl_loop foo> > <tmpl_if __ODD__><tr></tmpl_if> > <td><tmpl_var foobar></td> > <tmpl_if __LAST__><tmpl_if > __ODD__><td> </td></tmpl_if></tmpl_if> > <tmpl_unless __ODD__></tr></tmpl_if> > </tmpl_loop> > > The first if __ODD__ checks if it's the start of a new row - 1, 3, 5, > etc. > The unless __ODD__ checks if it's the end of the row - after 2, 4, 6, > etc. > The if __LAST__ && __ODD__ checks if it is the last entry in the list, > but not an even entry, meaning there will be one blank entry in the > table. > > This will only work with two columns. More than that isn't possible. > > Philip > Thank you for the comments. I have spent the last few hours developing a solution that seems to work. In my case, it ended up being 4 columns across (4x2) - so I needed a flexible solution. Here it is (Any comments on how to improve it are always welcome): <snip> $sql = qq{SELECT Caption, Thumbnail, ID From News ORDER BY Position ASC}; $sth = $dbh->prepare($sql) or bail_out(); $sth->execute(); $rv = $sth->rows; $get_data_sub = sub { my ($offset, $rows) = @_; my @return_array; for (my $x = $offset; $x < $rows + $offset; $x=$x+4) { $newsql = $sql . " LIMIT $x, 4"; $sth = $dbh->prepare($newsql) or bail_out(); $sth->execute() or bail_out(); my @rv; while(($Caption, $Thumbnail, $ID) = $sth->fetchrow_array()){ push @rv, {Caption => $Caption, Thumbnail => $Thumbnail, ID => $ID}; } push @return_array, {NEWSITEM => \@rv}; } $sth->finish() or bail_out(); $dbh->disconnect() or bail_out(); return \@return_array; }; $pager = HTML::Pager->new( query => $co, get_data_callback => $get_data_sub, rows => $rv, page_size => 8, template => $template ); </snip> Roy |
From: Philip S T. <phi...@gm...> - 2002-08-08 04:46:50
|
On Wed, 7 Aug 2002, Roy wrote: > I am writing a script that displays data in a 2-column format. I am using > HTML::Pager in order to only display a certain amount of records per page. > Given that, what is the best method to loop through the records and > retrieve, essentially two records per HTML table row. I do this all the time. <tmpl_loop foo> <tmpl_if __ODD__><tr></tmpl_if> <td><tmpl_var foobar></td> <tmpl_if __LAST__><tmpl_if __ODD__><td> </td></tmpl_if></tmpl_if> <tmpl_unless __ODD__></tr></tmpl_if> </tmpl_loop> The first if __ODD__ checks if it's the start of a new row - 1, 3, 5, etc. The unless __ODD__ checks if it's the end of the row - after 2, 4, 6, etc. The if __LAST__ && __ODD__ checks if it is the last entry in the list, but not an even entry, meaning there will be one blank entry in the table. This will only work with two columns. More than that isn't possible. Philip |
From: Roy <ro...@ir...> - 2002-08-07 23:32:21
|
Hello, I am writing a script that displays data in a 2-column format. I am using HTML::Pager in order to only display a certain amount of records per page. Given that, what is the best method to loop through the records and retrieve, essentially two records per HTML table row. To clarify the above, here is a snippet <html page> <HTML> <HEAD> </HEAD> <BODY> <TABLE> <TR> <TD> RECORD 1 </TD> <TD> RECORD 2 </TD> <TR> <TR> <TD> RECORD 3 </TD> <TD> RECORD 4 </TD> <TR> </TABLE> </BODY> </HTML> </html page> Please keep in mind that there may be an even or odd amount of records. Any ideas? TIA. Roy Rubin Irubin Consulting - Internet Solutions ro...@ir... Phone (310) 402-0120 http://www.irubin.com/ |
From: Kenny S. <ke...@jo...> - 2002-08-06 15:34:01
|
> This means that you should copy the result from > fetchrow_hashref to your array, for example: > > while (my $data = $sth->fetchrow_hashref ('NAME_lc')) { > push (@$rows, { $data }); > } Doh, you're right, someone on this list told me that once before, but I haven't done much since then, so I forgot about it. > Better still, take the effort out of your code and let > the (new) function fetchall_arrayref do it all for you: > > my $rows = $sth->fetchall_arrayref ({}); Yeah, I use this one myself usually, but I thought the above code was easier to understand as an example. Todd, Ok, now that I understand your question (and was reminded of the above)... Does 'uname' have anything to do with the database data? If so, and it's not complicated, I usually just add an item into the select statement... I use the following code to select employees out of the database and set one of them to "selected" so I can populate a select box with the data (the code is stripped down to provide an easier to read example): ----------------- snip ---------------------------- $sql = "SELECT id,name,IF(id=?,1,0) as is_selected ". "FROM employee WHERE status='active" ; $sth = $dbh->prepare( $sql ) ; $sth->execute( $selected_employee_id ) ; $employee_list = $sth->fetchall_arrayref({}); ----------------- end ------------------------------ This way, you don't need to go back and add that one value in. If 'uname' is not a value you can really add to your select statment, then just do this: ----------------- snip ---------------------------- $sth = $dbh->prepare( $sql ) ; $sth->execute( @your_bind_vars ) ; $list = $sth->fetchall_arrayref({}) ; if ( scalar( @{$list} ) > 0 ) { foreach $item ( @{$list} ) { $item->{'uname'} = set_uname() ; } } ----------------- end ------------------------------ Kenny Smith |
From: Chris D. <Chr...@Ma...> - 2002-08-06 09:30:42
|
Kenny Smith wrote, on Tuesday, August 06, 2002 1:24 AM > while( $data = $sth->fetchrow_hashref() ) { > push( @{$rows} , $data ) ; > } The DBI documentation explicitly warns against storing the result from fetchrow_hashref() as part of a fetch loop: Currently, a new hash reference is returned for each row. This *will* *change* in the future to return the same hash ref each time, so don't rely on the current behaviour. This means that you should copy the result from fetchrow_hashref to your array, for example: while (my $data = $sth->fetchrow_hashref ('NAME_lc')) { push (@$rows, { $data }); } Better still, take the effort out of your code and let the (new) function fetchall_arrayref do it all for you: my $rows = $sth->fetchall_arrayref ({}); Chris -- Chris Davies, Manheim Online Tel. 0113 393-2004 Fax. 0870 444-0482. Mobile 07778 199069 |