html-template-users Mailing List for HTML::Template (Page 54)
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: Karen J. C. <si...@ph...> - 2004-04-17 16:57:10
|
On Sat, 17 Apr 2004, Puneet Kishor wrote: PK>Interesting. I have approached this always with the attitude that I PK>have to separate programming from display as much as possible. I've Yes, but is the data part of the "programming," or part of the "display?" In the case of this project, the data definition is part of the programming for a *different* set of scripts, but this script is the UI for settings maintenance (for/by the user). Because the nontechnical-user--friendliness is the paramount issue, it's the HTML designer who gets to decide how the stuff is presented as far as layout, the order things get handled on, and so on, so the script has to follow the pattern set by the display in this case. PK>sure... the user's actions would arrive to you (the cgi) as cgi params. PK>Most all decisions can be made based on those. In fact, even before PK>that, quite a few illogical user acts can be trapped with judicious use PK>of javascript. I'm not so concerned about illogical, but rather about hostile. Because it's going to be a public Internet app, I have to assume that some users are going to look at the code and submit data that deliberately violates it. So the script has to know what list selections are permissible (presently I feed those *from* the script via TMPL_LOOP), things like that. Client-side checking absolutely can't be trusted to do that. -- Karen J. Cravens si...@ph... |
From: Puneet K. <pk...@ei...> - 2004-04-17 16:44:46
|
On Apr 17, 2004, at 11:25 AM, Karen J. Cravens wrote: > On Sat, 17 Apr 2004, Puneet Kishor wrote: > > PK>What is/are a typical circumstance(s) where I would not already know > PK>what vars exist in a template and would want to use query to find > out? > > It's the split between template and programming thing. I've considered On Apr 17, 2004, at 11:18 AM, Roger Burton West wrote: > On Sat, Apr 17, 2004 at 11:10:35AM -0500, Puneet Kishor wrote: > >> What is/are a typical circumstance(s) where I would not already know >> what vars exist in a template and would want to use query to find out? > > The most obvious case is the one in which someone else is being given > the HTML design part of the job. Interesting. I have approached this always with the attitude that I have to separate programming from display as much as possible. I've just finished a relatively complicated app -- a single cgi script about 2000 lines long, and about 45 different templates. My approach has been to create the templates in such a way that they could exist as a standalone website even if there was no H-T involved. In other words, if a designer-type decided to load the entire templates folder with its stylesheets and javascripts and whatnot in a designer-type program (GoLive or Dreamweaver, etc.), a complete, well-formed website would manifest, of course, with tmpl_vars intact. It may look a bit kooky since tables won't be fleshed out, and a few unavoidable tmpl_ifs won't be logic-ed out, but nonetheless -- it would be a website with all its links and scripts and behaviors and whatnot. On Apr 17, 2004, at 11:25 AM, Karen J. Cravens wrote: > > I can't speak to the original poster's exact situation, but I've been > mulling over something along these lines. Problem *I* have is that the > script really needs to know more than just the parm name... it should > know > whether the end-user obeyed the form length, actually picked one of the > SELECT options or hand-built a bogus submission, things like that. sure... the user's actions would arrive to you (the cgi) as cgi params. Most all decisions can be made based on those. In fact, even before that, quite a few illogical user acts can be trapped with judicious use of javascript. On Apr 17, 2004, at 11:18 AM, Roger Burton West wrote: > A secondary case is general debugging - if the template passes the > syntax check but doesn't show the expected results, it's helpful to be > able to show H::T's idea of its internal structure. > ok. This might make sense. I've usually just rolled my own debug breakpoints simply because I am really scared of the perl debugger. Thanks folks, for your insights. |
From: petersm <pe...@ve...> - 2004-04-17 16:38:34
|
Puneet Kishor <pk...@ei...> > > I am curious too... I've been using H-T for about a year and a half, > and I've never had to query the template. My assumption is that params > in the template are assigned by me, so I would automatically know what > vars exist in the template. > > What is/are a typical circumstance(s) where I would not already know > what vars exist in a template and would want to use query to find out? > > Thanks. Querying the template allows you to be able to create another layer of abstraction between the code and the template. We use it to create a custom 'TemplateLoader' that will look at a given template, and by the naming convention that we use on the vars and loops it will actually create the SQL statements, query the database and load the templates. The only thing we have to remember is to use the nameing convention for the vars. This works for about 95% of the occassions that we use H::T and then the other %5 we use it more straight forward. The benefits of this are that if we want to add some more data to the template (an extra column or field or something) we just add the correct TMPL_VAR to the template and then the TemplateLoader does the rest. We don't have to change the code. If you're curiosity is piqued, then you can check out how we do this at cheesepizza.venzia.com. The module in question is named 'CheesePizza::TemplateLoader'. Michael Peters Venzia |
From: Karen J. C. <si...@ph...> - 2004-04-17 16:25:04
|
On Sat, 17 Apr 2004, Puneet Kishor wrote: PK>What is/are a typical circumstance(s) where I would not already know PK>what vars exist in a template and would want to use query to find out? It's the split between template and programming thing. I've considered this myself... suppose you're wanting to build a form, with a great deal of customization involved layout/graphics wise (so that none of the form-building tools are really adequate). Suppose further that the script doesn't really care (much) what's in the form, because its only job is to save the settings in a file. I can't speak to the original poster's exact situation, but I've been mulling over something along these lines. Problem *I* have is that the script really needs to know more than just the parm name... it should know whether the end-user obeyed the form length, actually picked one of the SELECT options or hand-built a bogus submission, things like that. I haven't quite figured out whether I should write something that analyzes a read-in template to produce verification code (and if so, whether it should happen on the fly or not), use a meta-template to produce both the verification code and HTML fragments, or what. -- Karen J. Cravens si...@ph... |
From: Roger B. W. <ro...@fi...> - 2004-04-17 16:18:27
|
On Sat, Apr 17, 2004 at 11:10:35AM -0500, Puneet Kishor wrote: >What is/are a typical circumstance(s) where I would not already know >what vars exist in a template and would want to use query to find out? The most obvious case is the one in which someone else is being given the HTML design part of the job. A secondary case is general debugging - if the template passes the syntax check but doesn't show the expected results, it's helpful to be able to show H::T's idea of its internal structure. Roger |
From: Puneet K. <pk...@ei...> - 2004-04-17 16:10:36
|
On Apr 17, 2004, at 10:39 AM, <al...@lo...> wrote: > I don't know what you are trying to do, > but that doesn't seem like a good thing. > It feels like you're making the code overly complex. > You should think it through thoroughly to see > if theres a better way. > > Alan. > > > ----- Original Message ----- > From: "Kapoor, Nishikant" <nis...@xc...> > To: "H::T (E-mail)" <htm...@li...> > Sent: Friday, April 16, 2004 6:39 AM > Subject: [htmltmpl] how to determine if tmpl_var exists in a loop? > > > I have used > > if ($template->query(name => 'tmplVar')) {} > > to check if a tmpl_var exists in the template or not. > > How/what do I use for a tmpl_var inside a tmpl_loop? > > I am curious too... I've been using H-T for about a year and a half, and I've never had to query the template. My assumption is that params in the template are assigned by me, so I would automatically know what vars exist in the template. What is/are a typical circumstance(s) where I would not already know what vars exist in a template and would want to use query to find out? Thanks. |
From: <al...@lo...> - 2004-04-17 15:40:10
|
I don't know what you are trying to do, but that doesn't seem like a good thing. It feels like you're making the code overly complex. You should think it through thoroughly to see if theres a better way. Alan. ----- Original Message -----=20 From: "Kapoor, Nishikant" <nis...@xc...> To: "H::T (E-mail)" <htm...@li...> Sent: Friday, April 16, 2004 6:39 AM Subject: [htmltmpl] how to determine if tmpl_var exists in a loop? I have used=20 if ($template->query(name =3D> 'tmplVar')) {} to check if a tmpl_var exists in the template or not. How/what do I use for a tmpl_var inside a tmpl_loop? Thanks Nishi ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=3Dick _______________________________________________ Html-template-users mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Kapoor, N. <nis...@xc...> - 2004-04-16 20:31:19
|
Sorry, I should have checked the docs first. Anyway, thanks for the = help.=20 This is exactly what I was looking for if ($template->query(name =3D> ['tmplLoop', 'tmplVar'])) {} Thanks Nishi > -----Original Message----- > From: Roger Burton West [mailto:ro...@fi...] > Sent: Friday, April 16, 2004 9:02 AM > To: H::T (E-mail) > Subject: Re: [htmltmpl] how to determine if tmpl_var exists in a loop? >=20 >=20 > On Fri, Apr 16, 2004 at 08:39:05AM -0500, Kapoor, Nishikant wrote: > >I have used=20 > >if ($template->query(name =3D> 'tmplVar')) {} > >to check if a tmpl_var exists in the template or not. > >How/what do I use for a tmpl_var inside a tmpl_loop? >=20 > Recurse or append parameters. See the documentation, under: >=20 > "query()" also allows you to get a list of parameters > inside a loop (and inside loops inside loops). >=20 > which explains it very clearly. >=20 > Roger >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > = administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= ck > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users >=20 >=20 |
From: Roger B. W. <ro...@fi...> - 2004-04-16 14:01:54
|
On Fri, Apr 16, 2004 at 08:39:05AM -0500, Kapoor, Nishikant wrote: >I have used >if ($template->query(name => 'tmplVar')) {} >to check if a tmpl_var exists in the template or not. >How/what do I use for a tmpl_var inside a tmpl_loop? Recurse or append parameters. See the documentation, under: "query()" also allows you to get a list of parameters inside a loop (and inside loops inside loops). which explains it very clearly. Roger |
From: Kapoor, N. <nis...@xc...> - 2004-04-16 13:39:22
|
I have used=20 if ($template->query(name =3D> 'tmplVar')) {} to check if a tmpl_var exists in the template or not. How/what do I use for a tmpl_var inside a tmpl_loop? Thanks Nishi |
From: Sam T. <sa...@tr...> - 2004-04-15 14:53:37
|
On Wed, 14 Apr 2004, C Hagstrom wrote: > But my concern is that the approach would not > be "server friendly". That said, I'm thinking that the overhead > for template calls is so small, I need not be concerned. I'm not sure what you mean by "server friendly", but the only way to know anything about performance is to measure it. I recommend you get comfortable with Benchmark.pm and Devel::DProf. Using these tools you can find out exactly how long it takes to call new() on your templates. But what the heck, here's a couple hints anyway: new() takes much more time on larger and more complicated templates. You can reduce this time to almost nothing using caching and pre-compiling your templates. -sam |
From: Mathew R. <mat...@re...> - 2004-04-15 07:25:00
|
If you use the caching options of H::T, then wont need to care where you = call new(), as H::T will automatically use a previously parsed version = of the template from the cache, ie. the impact of call new() on a = previously parsed template, is nearly zero. Read up on the caching options within the H::T perldoc; you should find = one of the type which would suite your application environment. regards, Mathew > Wondering if anyone has input regarding the use of: >=20 > HTML::Template->new >=20 > It would seem (to me) that from a performance standpoint, > only calling a template as it is needed is the most efficient > approach. >=20 > My question has to do with the actual impact of > HTML::Template->new >=20 > In a script, when I only use a given template one time, > I only call it in the one location where it's needed >=20 > When the template is used globally (every time the > script is fired off), I call the template at the beginning > of the script - one time. >=20 > My question has to do with templates that are potentially > used in many areas of the script, even though only once. > In other words, there may be various ways the script > can be triggered that will require a given template (and > many ways the script can be called where the template > isn't needed). >=20 > To avoid code clutter, what I'd like to do is call all my > templates in one spot: >=20 > my $temp1 =3D HTML::Template->new( etc ... > my $temp2 =3D HTML::Template->new( etc ... > my $temp3 =3D HTML::Template->new( etc ... >=20 > But my concern is that the approach would not > be "server friendly". That said, I'm thinking that the overhead > for template calls is so small, I need not be concerned. >=20 > Hopefully, some on the list can enlighten me. >=20 > Carl Hagstrom >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > = administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= ck > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: C H. <hag...@ep...> - 2004-04-15 05:57:39
|
Wondering if anyone has input regarding the use of: HTML::Template->new It would seem (to me) that from a performance standpoint, only calling a template as it is needed is the most efficient approach. My question has to do with the actual impact of HTML::Template->new In a script, when I only use a given template one time, I only call it in the one location where it's needed When the template is used globally (every time the script is fired off), I call the template at the beginning of the script - one time. My question has to do with templates that are potentially used in many areas of the script, even though only once. In other words, there may be various ways the script can be triggered that will require a given template (and many ways the script can be called where the template isn't needed). To avoid code clutter, what I'd like to do is call all my templates in one spot: my $temp1 = HTML::Template->new( etc ... my $temp2 = HTML::Template->new( etc ... my $temp3 = HTML::Template->new( etc ... But my concern is that the approach would not be "server friendly". That said, I'm thinking that the overhead for template calls is so small, I need not be concerned. Hopefully, some on the list can enlighten me. Carl Hagstrom |
From: Mathew R. <mat...@re...> - 2004-04-14 21:48:13
|
> >What has Perl's string interpolation got to do with DBI? > > > >"SELECT * FROM $working_tbl WHERE first=3D'one' ORDER BY Location" > > > >The variable $working_tbl will be interpolated by Perl, long before = DBI=20 > >ever gets to see the SQL statement, due to the double-quote. >=20 > $working_tbl may come from some kind of user input, which opens you up = to=20 > SQL injection attacks. Most databases don't allow placeholders for = the=20 > table name. It's best to use DBI->quote() whenever you absolutely = must=20 > interpolate a variable into an SQL statement. no - you should never take any kind of user input without doing input = validation -> otherwsie you are asking for trouble. Also, DBI->quote() will not help with the example written above, as Perl = will interpolate the vairable into to string, due to the double-quotes. = You are correct that most databases wont use variable table names, but = the syntax was not written like: "SELECT * FROM ? WHERE ..." Mathew |
From: Timm M. <tm...@ag...> - 2004-04-14 12:54:13
|
At 09:21 AM 4/14/04 +1000, Mathew Robertson wrote: > > > I can get the results to print directly with this code: > > > > > > $sth = $dbh->prepare ("SELECT * FROM $working_tbl WHERE first='one' > > > ORDER BY Location"); > > > $sth->execute (); > > > while ( my $hash_ref = $sth->fetchrow_hashref ) { > > > print "ID: $hash_ref->{'ID'} -- Name: $hash_ref->{'Name'} > > > (etc....) <br>\n"; > > > } > > > this is cool, but do note that the DBI docs generally advise against the > > use of a variable table name (well... I understand them to be advising > > against) as it doesn't allow for creating a plan and optimizing the > > query. Anyway... > >What has Perl's string interpolation got to do with DBI? > >"SELECT * FROM $working_tbl WHERE first='one' ORDER BY Location" > >The variable $working_tbl will be interpolated by Perl, long before DBI >ever gets to see the SQL statement, due to the double-quote. $working_tbl may come from some kind of user input, which opens you up to SQL injection attacks. Most databases don't allow placeholders for the table name. It's best to use DBI->quote() whenever you absolutely must interpolate a variable into an SQL statement. >Mathew > > >------------------------------------------------------- >This SF.Net email is sponsored by: IBM Linux Tutorials >Free Linux tutorial presented by Daniel Robbins, President and CEO of >GenToo technologies. Learn everything from fundamentals to system >administration. >_______________________________________________ >Html-template-users mailing list >Htm...@li... >https://lists.sourceforge.net/lists/listinfo/html-template-users |
From: Jeff C. <oka...@po...> - 2004-04-14 08:09:12
|
On Tue, 13 Apr 2004 14:01:35 -0400 (EDT) , Sam Tregar <sa...@tr...> wrote: >On Tue, 13 Apr 2004, Jeff Capes wrote: > >> HTML::Template->new() : Syntax error in <TMPL_*> tag at >> /fake/path/for/non/file/template : 1. at >> /usr/lib/perl5/site_perl/5.8.0/HTML/Template.pm line 2243. > >Any chance you're running Perl 5.8.0 on Redhat 8 or Redhat 9? If so, >you might have a broken Perl install. Red Hat 9. > >> my $tmpl; >> >> $tmpl = &get_template($tmpl); > >What do you see in your error log if you insert this here: > > print STDERR "-----TEMPLATE START----\n\n$tmpl\n\n---TEMPLATE END----\n"; > >I'm interested to see if $tmpl contains what you think it does. It did. I've tested a workaround for the problem by setting LANG=en_GB. The workaround worked, so I edited /etc/sysconfig/i18n to make it permanent. This also fixed Date::Manip. Thanks to everyone who helped! ___________________________________________________ Reduce your company's IT costs today with Officemaster. Sign up for a free trial! http://www.officemaster.net |
From: Puneet K. <pk...@ei...> - 2004-04-14 00:18:10
|
On Apr 13, 2004, at 6:21 PM, Mathew Robertson wrote: >>> I can get the results to print directly with this code: >>> >>> $sth = $dbh->prepare ("SELECT * FROM $working_tbl WHERE first='one' >>> ORDER BY Location"); >>> $sth->execute (); >>> while ( my $hash_ref = $sth->fetchrow_hashref ) { >>> print "ID: $hash_ref->{'ID'} -- Name: $hash_ref->{'Name'} >>> (etc....) <br>\n"; >>> } > >> this is cool, but do note that the DBI docs generally advise against >> the >> use of a variable table name (well... I understand them to be advising >> against) as it doesn't allow for creating a plan and optimizing the >> query. Anyway... > > What has Perl's string interpolation got to do with DBI? > > "SELECT * FROM $working_tbl WHERE first='one' ORDER BY Location" > > The variable $working_tbl will be interpolated by Perl, long before > DBI ever gets to see the SQL statement, due to the double-quote. > > you are correct, and my advise was half-baked. The assertion I made holds true when doing multiple queries using bind variables, and hence, I try to stay away from variable-izing table names... that is where my advise came from and it really doesn't apply to Carl's case. But, as they say... you gotta do what you gotta do. |
From: Mathew R. <mat...@re...> - 2004-04-13 23:21:31
|
> > I can get the results to print directly with this code: > >=20 > > $sth =3D $dbh->prepare ("SELECT * FROM $working_tbl WHERE = first=3D'one'=20 > > ORDER BY Location"); > > $sth->execute (); > > while ( my $hash_ref =3D $sth->fetchrow_hashref ) { > > print "ID: $hash_ref->{'ID'} -- Name: $hash_ref->{'Name'} =20 > > (etc....) <br>\n"; > > } > this is cool, but do note that the DBI docs generally advise against = the=20 > use of a variable table name (well... I understand them to be advising = > against) as it doesn't allow for creating a plan and optimizing the=20 > query. Anyway... What has Perl's string interpolation got to do with DBI?=20 "SELECT * FROM $working_tbl WHERE first=3D'one' ORDER BY Location" The variable $working_tbl will be interpolated by Perl, long before DBI = ever gets to see the SQL statement, due to the double-quote. Mathew |
From: Sam T. <sa...@tr...> - 2004-04-13 18:02:55
|
On Tue, 13 Apr 2004, Jeff Capes wrote: > HTML::Template->new() : Syntax error in <TMPL_*> tag at > /fake/path/for/non/file/template : 1. at > /usr/lib/perl5/site_perl/5.8.0/HTML/Template.pm line 2243. Any chance you're running Perl 5.8.0 on Redhat 8 or Redhat 9? If so, you might have a broken Perl install. > my $tmpl; > > $tmpl = &get_template($tmpl); What do you see in your error log if you insert this here: print STDERR "-----TEMPLATE START----\n\n$tmpl\n\n---TEMPLATE END----\n"; I'm interested to see if $tmpl contains what you think it does. -sam |
From: Puneet K. <pk...@ei...> - 2004-04-13 16:47:10
|
C Hagstrom wrote: > Thanks to all for the suggestions > (the speed and number of the responses was great) > > I'm going to run with Puneet's suggestion: > > # Fetch the results as a ref to an AofH > my $res = $sth->fetchall_arrayref({}); > # Assign the ref to a var in the template > $t->param(RES => $res); > > for the simple reason: > > "Specify the column names you want to retrieve, > and the column names automatically become > the names of the TMPL_VARs." > > This seems the simplest way to go for my application > From what I understand, working with hash_ref 's > is supposed to be inefficient (performance-wise), > but in my case, I'm pursuing such a light > weight database that I don't think it's an issue. ya, possibly. As you say, given your situation (and, I daresay, for most common situations), simplicity weighs heavier than speed. You can always achieve more speed by tweaking other things (faster database, better db structure, cached templates, mod_perl or some other persistent perl, faster hardware and more memory). I always, always, err toward simplicity. Good luck. |
From: C H. <hag...@ep...> - 2004-04-13 16:32:32
|
Thanks to all for the suggestions (the speed and number of the responses was great) I'm going to run with Puneet's suggestion: # Fetch the results as a ref to an AofH my $res = $sth->fetchall_arrayref({}); # Assign the ref to a var in the template $t->param(RES => $res); for the simple reason: "Specify the column names you want to retrieve, and the column names automatically become the names of the TMPL_VARs." This seems the simplest way to go for my application From what I understand, working with hash_ref 's is supposed to be inefficient (performance-wise), but in my case, I'm pursuing such a light weight database that I don't think it's an issue. Carl Hagstrom hag...@ep... |
From: Keith J. <kja...@ey...> - 2004-04-13 15:27:46
|
Here is a code snippet that uses fetchrow_hashref and pushs the records into an array to pass to a template... ------------------------------------ my $sth = $dbh->prepare(qq(select * from shopping_cart)); $sth->execute(); while($hash_ref = $sth->fetchrow_hashref()){ push(@records, $hash_ref); } use HTML::Template; my $template = new HTML::Template(filename=>cart.html); $template->param(records => \@records); print $template->output(); ------------------------------------- Hope that helps.... On Tue, 2004-04-13 at 10:38, C Hagstrom wrote: > I'm hoping for some conceptual help here.... > I have tried to find references to my question without > success ( the list-archive link appears not to be working). > > System info: Linux - Perl - MySql > > I'm fairly comfortable at this stage with H::T, > and am also fairly comfortable with the DBI/MySql > interface. > > I have a script that queries the database, and pulls > information from numerous records ... in other words, > it grabs and displays all the record information > for a selected group of records. > > I can get the results to print directly with this code: > > $sth = $dbh->prepare ("SELECT * FROM $working_tbl WHERE first='one' ORDER > BY Location"); > $sth->execute (); > while ( my $hash_ref = $sth->fetchrow_hashref ) { > print "ID: $hash_ref->{'ID'} -- Name: > $hash_ref->{'Name'} (etc....) <br>\n"; > } > > And before I became an H::T convert, I would use > the above approach, and craft the HTML output > directly in the script. > > Now that I am an H::T convert, I'm looking for guidance > on how best to handle the database output so I can > take advantage of the <TMPL_LOOP> feature in H::T > > I tried googling, and did find a few references on this topic, > but I had difficulty understanding them. I'm no wizard when > it comes to the object oriented side of things, or MySql > retrievals in general. > > I have found that (for me) retrieving data using fetchrow_hashref > is easier 'cause the info can be gleaned using the field names, > where (it seems to me), fetchrow_array is based on the numerical > order/array-reference of the items, and is easier for me to screw up. > > At any rate, I think I'm close to understanding it, but am hoping > someone can explain the process in a pretty basic way. I think > I understand the fundamentals, but am really struggling > trying to understand how the info gets tossed into some > sort of container so it can be sent out to a <TEMPL_LOOP> > call in the related template. > > > Carl Hagstrom > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users -- Keith Jackson <kja...@ey...> |
From: Roger B. W. <ro...@fi...> - 2004-04-13 15:13:39
|
On Tue, Apr 13, 2004 at 12:43:55PM +0100, Jeff Capes wrote: >I'm having problems with scalarref. I'm not. Running Perl 5.6.1, H::T 2.5, and your code (modified only to change the filename), I get: ### HTML::Template Debug ### In _parse: ### HTML::Template Debug ### /fake/path/for/non/file/template : line 2 : LOOP employee_info start ### HTML::Template Debug ### /fake/path/for/non/file/template : line 4 : parsed VAR name ### HTML::Template Debug ### /fake/path/for/non/file/template : line 6 : parsed VAR job ### HTML::Template Debug ### /fake/path/for/non/file/template : line 8 : LOOP end ### HTML::Template Debug ### In output which is as it should be. Roger |
From: petersm <pe...@ve...> - 2004-04-13 15:12:01
|
C Hagstrom wrote: > I'm hoping for some conceptual help here.... > I have tried to find references to my question without > success ( the list-archive link appears not to be working). > > > I can get the results to print directly with this code: > > $sth = $dbh->prepare ("SELECT * FROM $working_tbl WHERE first='one' ORDER > BY Location"); > $sth->execute (); > while ( my $hash_ref = $sth->fetchrow_hashref ) { > print "ID: $hash_ref->{'ID'} -- Name: > $hash_ref->{'Name'} (etc....) <br>\n"; > } > > > Now that I am an H::T convert, I'm looking for guidance > on how best to handle the database output so I can > take advantage of the <TMPL_LOOP> feature in H::T you can use something like this to get the structure from DBI $sth = $dbh->prepare("SELECT FirstName, LastName FROM Person WHERE ..."); #this will get an array of hashrefs my $result = $sth->fetchall_arrayref({}); then you would put that structure into your template like so... my $tmpl->HTML::Template->new(..); $tmpl->param('Person_Loop' => $result); and then your template could look like this <TMPL_LOOP Person_Loop> Hello, My name is <TMPL_VAR FirstName> <TMPL_VAR LastName>.<br /> </TMPL_LOOP> Does that help? Michael Peters Venzia |
From: Puneet K. <pk...@ei...> - 2004-04-13 15:03:30
|
C Hagstrom wrote: > I'm hoping for some conceptual help here.... .. > > I have a script that queries the database, and pulls > information from numerous records ... in other words, > it grabs and displays all the record information > for a selected group of records. > > I can get the results to print directly with this code: > > $sth = $dbh->prepare ("SELECT * FROM $working_tbl WHERE first='one' > ORDER BY Location"); > $sth->execute (); > while ( my $hash_ref = $sth->fetchrow_hashref ) { > print "ID: $hash_ref->{'ID'} -- Name: $hash_ref->{'Name'} > (etc....) <br>\n"; > } > this is cool, but do note that the DBI docs generally advise against the use of a variable table name (well... I understand them to be advising against) as it doesn't allow for creating a plan and optimizing the query. Anyway... > And before I became an H::T convert, I would use > the above approach, and craft the HTML output > directly in the script. > > Now that I am an H::T convert, I'm looking for guidance > on how best to handle the database output so I can > take advantage of the <TMPL_LOOP> feature in H::T I have posted several times about how to do this using a very simple approach -- the fetchall_arrayref({}) method in DBI. This fetches a ref to an array of hashes... exactly what the TMPL_LOOP wants. # Create the sql query my $sql = <<SQL; SELECT col1, col2, col3 FROM my_working_tbl WHERE first = 'one' ORDER BY Location SQL # Create the statement handle and execute it my $sth = $dbh->prepare(qq{$sql}); $sth->execute; # Fetch the results as a ref to an AofH my $res = $sth->fetchall_arrayref({}); # Assign the ref to a var in the template $t->param(RES => $res); Then in your template -- <table> <tr><th>Col1</th><th>Col2</th><th>Col2</th></tr> <TMPL_LOOP RES> <tr> <td><TMPL_VAR COL1></td> <td><TMPL_VAR COL2></td> <td><TMPL_VAR COL3></td> </tr> </TMPL_LOOP> </table> Keep in mind -- you can't use SELECT * (which is inefficient for the database anyway). Specify the column names you want to retrieve, and the column names automatically become the names of the TMPL_VARs. I hope this helps. It really doesn't get any simpler and basic than this. Let us know if you need further help. Ya, the archive seems to be down, but when it comes back up (if it does), there are a lot of good discussions there. Good luck. |