html-template-users Mailing List for HTML::Template (Page 102)
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: <no...@ci...> - 2002-08-06 01:49:26
|
Wrote by "Kenny Smith" in 2002/08/06 09:23 JST >> -------- snip ---------- >> my $template = HTML::Template->new( filename => 'showclient.html' ) ; >> my $rc = $sth->execute() ; >> my ( $data , $rows ); >> while( $data = $sth->fetchrow_hashref() ) { >> push( @{$rows} , $data ) ; >> } >> $template->param( { results => $rows } ) ; >> print $template->output() ; >> -------- end ------------ Hum.. -------- snip ---------- my $template = HTML::Template->new( filename => 'showclient.html' ); $template->param( results => $dbh->selectall_arrayref(q{ SELECT your sql AS "TMPL_KEY" }, {Slice=>{}}, PARAMS), ); print $template->output() ; -------- end ------------ You don't need `prepare'. But if you need `prepare', use fetchall_arrayref(maybe:-). |
From: Todd S. <zo...@pa...> - 2002-08-06 01:05:11
|
Hi Kenny, Thanks for the suggestion but I think I need to try to explain better what I'm trying to accomplish. I have a template as follows: ----------------Temp Snip------------------ <TMPL_LOOP NAME="results"> <tr> <td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='cid'></FONT></th> <td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='companyName'></FONT></th> <td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='address'></FONT></th> <td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='city'></FONT></th> <td><FONT FACE="ARIAL" SIZE="2"><TMPL_VAR NAME='phone'></FONT></th> <Td><form method=post action="/cgi-bin/sv.cgi"> <input type=hidden name=rm value="selectClient"> <input type=hidden name=cid value="<TMPL_VAR NAME='cid'>"> <input type=hidden name=uname value="<TMPL_VAR NAME='uname'>"> <input type=submit value="Select"></td> </tr> </TMPL_LOOP> ----------------end------------------------ All the above variables are filled from my SQL SELECT statement, except for "uname" which is a tag I want to add to each row. How do I add that value to what I'm getting back with my "$data = $sth->fetchrow_hashref()" statement so that it gets filled in when H::T runs the above loop? Thanks! -----Original Message----- From: htm...@li... [mailto:htm...@li...]On Behalf Of Kenny Smith Sent: Monday, August 05, 2002 5:24 PM To: zo...@pa...; htm...@li... Subject: RE: [htmltmpl] Adding to a row in a loop Hi Todd, I'm not exactly sure what you are trying to do that you aren't actually accomplishing with the code you provided, but in any case, I would suggest something more like this: -------- snip ---------- my $template = HTML::Template->new( filename => 'showclient.html' ) ; my $rc = $sth->execute() ; my ( $data , $rows ); while( $data = $sth->fetchrow_hashref() ) { push( @{$rows} , $data ) ; } $template->param( { results => $rows } ) ; print $template->output() ; -------- end ------------ It's a good idea to never set $_ yourself... you should always use your own variable. Kenny -----Original Message----- From: htm...@li... [mailto:htm...@li...]On Behalf Of Todd Schacherl Sent: Monday, August 05, 2002 4:53 PM To: htm...@li... Subject: [htmltmpl] Adding to a row in a loop Hi Folks, I think this might be a basic PERL question but it does involve H::T. :o) But maybe somebody here can help me anyway...I'm using the loop ability with H::T to print out rows where each row is a form. I want to add a tag field for each row with the same data for that field in each row. How do I push that into the $rows that I pass to H::T? my $rc = $sth->execute(); my $tmpl_obj; # prepare a data structure for HTML::Template my $rows; push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); # instantiate the template and substitute the values $tmpl_obj = $self->load_tmpl('showclient.html'); $tmpl_obj->param(results => $rows); Thanks in advance, Todd Schacherl ht...@zo... ------------------------------------------------------- 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: Kenny S. <ke...@jo...> - 2002-08-06 00:31:29
|
Hi Todd, I'm not exactly sure what you are trying to do that you aren't actually accomplishing with the code you provided, but in any case, I would suggest something more like this: -------- snip ---------- my $template = HTML::Template->new( filename => 'showclient.html' ) ; my $rc = $sth->execute() ; my ( $data , $rows ); while( $data = $sth->fetchrow_hashref() ) { push( @{$rows} , $data ) ; } $template->param( { results => $rows } ) ; print $template->output() ; -------- end ------------ It's a good idea to never set $_ yourself... you should always use your own variable. Kenny -----Original Message----- From: htm...@li... [mailto:htm...@li...]On Behalf Of Todd Schacherl Sent: Monday, August 05, 2002 4:53 PM To: htm...@li... Subject: [htmltmpl] Adding to a row in a loop Hi Folks, I think this might be a basic PERL question but it does involve H::T. :o) But maybe somebody here can help me anyway...I'm using the loop ability with H::T to print out rows where each row is a form. I want to add a tag field for each row with the same data for that field in each row. How do I push that into the $rows that I pass to H::T? my $rc = $sth->execute(); my $tmpl_obj; # prepare a data structure for HTML::Template my $rows; push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); # instantiate the template and substitute the values $tmpl_obj = $self->load_tmpl('showclient.html'); $tmpl_obj->param(results => $rows); Thanks in advance, Todd Schacherl ht...@zo... |
From: Cory T. <ct...@on...> - 2002-08-06 00:23:54
|
1. Sorry this is HTML E-mail. I've been using this VS.NET IDE (ugh,) which pastes very messy unless Outlook is in HTML mode. Sorry again, I know, I hate me too. 2. I am thinking that you need help building an Array of Hashes for use in a loop. We want to assemble each record from the database and then append it to our loop construct. If I am incorrect, disregard this message. [[[[[[[[ snip ]]]]]]]] my $sth = $dbh -> prepare('select note_id, note_title, note_text, course_id, module_id, section_id, page_id, user_id from tblNotes where user_id = ? and course_id = ?'); $sth->execute($user_id, $course_id) or die "DB : Could not execute : $DBI::errstr"; my @note_index; while (my @rc = $sth->fetchrow_array() ) { my %results; %results->{'note_id'} = $rc[0]; %results->{'note_title'} = $rc[1]; push @note_index, \%results; } $sth->finish( ); return @note_index; [[[[[[[[ snip ]]]]]]]] I would later take @note_index and $body->( NOTES => \@note_index ) ; > > I think this might be a basic PERL question but it does involve H::T. :o) > But maybe somebody here can help me anyway...I'm using the loop > ability with > H::T to print out rows where each row is a form. I want to add a > tag field > for each row with the same data for that field in each row. How do I push > that into the $rows that I pass to H::T? You want to use an array of hashes. You make an array, and push the hash ref onto it. You could also unshift it. > > my $rc = $sth->execute(); > my $tmpl_obj; > > # prepare a data structure for HTML::Template > my $rows; > push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); That's obtuse ;) > # instantiate the template and substitute the values > $tmpl_obj = $self->load_tmpl('showclient.html'); > $tmpl_obj->param(results => $rows); I think I am doing the same thing above, but my array is returned to another module that manages putting it into the H:T > > Thanks in advance, Ok. - Cory |
From: simran <sim...@le...> - 2002-08-06 00:16:26
|
I'm not completely sure of the question you are asking, but assuming that: $data = [ $row1, $row2, ... ] where $rows are in the format: $row1 = { name1 => value1, name2 => value2, } and say you want to add "name3" going to "value3" in each row in $data you would do something like: my $new_data = []; foreach my $row (@$data) { $row->{'name3'} = 'value3'; push(@$new_data, $row); } simran. On Tue, 2002-08-06 at 09:52, Todd Schacherl wrote: > Hi Folks, > > I think this might be a basic PERL question but it does involve H::T. :o) > But maybe somebody here can help me anyway...I'm using the loop ability with > H::T to print out rows where each row is a form. I want to add a tag field > for each row with the same data for that field in each row. How do I push > that into the $rows that I pass to H::T? > > > my $rc = $sth->execute(); > my $tmpl_obj; > > # prepare a data structure for HTML::Template > my $rows; > push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); > > # instantiate the template and substitute the values > $tmpl_obj = $self->load_tmpl('showclient.html'); > $tmpl_obj->param(results => $rows); > > > Thanks in advance, > > Todd Schacherl > ht...@zo... > > One of the penalties for refusing to participate in politics is that you end > up being governed by your inferiors. -Plato > > > > ------------------------------------------------------- > 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: Todd S. <zo...@pa...> - 2002-08-05 23:53:19
|
Hi Folks, I think this might be a basic PERL question but it does involve H::T. :o) But maybe somebody here can help me anyway...I'm using the loop ability with H::T to print out rows where each row is a form. I want to add a tag field for each row with the same data for that field in each row. How do I push that into the $rows that I pass to H::T? my $rc = $sth->execute(); my $tmpl_obj; # prepare a data structure for HTML::Template my $rows; push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); # instantiate the template and substitute the values $tmpl_obj = $self->load_tmpl('showclient.html'); $tmpl_obj->param(results => $rows); Thanks in advance, Todd Schacherl ht...@zo... One of the penalties for refusing to participate in politics is that you end up being governed by your inferiors. -Plato |
From: Sam T. <sa...@tr...> - 2002-08-05 22:18:41
|
On Mon, 5 Aug 2002, Jeff Pelkey wrote: > The documentation for HTML-Template needs to be updated to reflect the new > mailing list address. You look at all the document on CPAN and Sourceforge > and they point you to the defunct mailing address at "htm...@li... > <mailto:htm...@li...> ", instead of this one. I stumbled across > the new address after several failed attempts by running a search against > the list. Thanks for the reminder! I meant to do that several weeks ago but finishing the book and moving got in the way... Expect a new release in the next few days. -sam |
From: Jeff P. <jp...@gr...> - 2002-08-05 21:42:47
|
Howdy! The documentation for HTML-Template needs to be updated to reflect the new mailing list address. You look at all the document on CPAN and Sourceforge and they point you to the defunct mailing address at "htm...@li... <mailto:htm...@li...> ", instead of this one. I stumbled across the new address after several failed attempts by running a search against the list. If someone could update these documents so others will not go through the same thing I did. I would be willing to do this if need be, just give any particulars. Thanx, Jeff Pelkey |
From: Philip S T. <phi...@gm...> - 2002-08-03 09:23:16
|
Sometime on Aug 2, Will assembled some asciibets to say: > Now my question... what do you folks think? Am I being too stubborn > here, or should I learn the CGI on form writing? Maybe it would > just be easiest to design my forms in DW and then set them into > H::T? Is this recommended? What are the pros and cons of this That's the way I do it - well, I use vi to make my forms, but basically, yeah, the forms are made as plain html and not built by CGI.pm - if that's what you were asking. I generally have something like this: <form ...> <table ...> ... <input type="text" name="name" value="<tmpl_var name='name' escape='html'>"> <tmpl_if error_name><span class="error"><tmpl_var error_name></span></tmpl_if> ... </table> </form> The single quotes in the tmpl_var parameters are so that vi's syntax highlighting doesn't get confused. In the case of checkboxes or select boxes, I have this: <select name="items"> <any default entry here> <tmpl_loop name="items"> <option value="<tmpl_var id>" <tmpl_if selected>selected</tmpl_if>><tmpl_var value></option> </tmpl_loop> </select> <tmpl_loop name="items"> <input type="checkbox" name="items" value="<tmpl_var id>" <tmpl_if selected>checked</tmpl_if>> <tmpl_var value> </tmpl_loop> That works for multiselect lists as well. The perl has to take care of setting selected for the correct entries, but that's a small thing. $ids = "10:3"; @list = map { $_->{'selected'} = ($ids =~ /(?:^|:)$_->{'id'}(?::|$)/); $_; } @list; -- Han Solo: Chewie and I will check it out, you two stay here. Luke Skywalker: Quietly. There may be more of them out there. Han Solo: Hey, it's me. |
From: Cory T. <ct...@on...> - 2002-08-03 02:19:57
|
> Now my question... what do you folks think? Am I > being too stubborn here, or should I learn the CGI on > form writing? Maybe it would just be easiest to > design my forms in DW and then set them into H::T? Is > this recommended? What are the pros and cons of this > approach? We are here because we have the option to design our forms (as many times for each business-logic component if we use CGI::Application) directly in HTML templates. Thus, we can use CSS & XHTML to make our forms _standard_ or we can make up some other method to make them look however we want. Heck, if you want to use <font /> and <blink /> tags, I do not care. HTML::Template won't either. As for my opinion, I do not really care what the designers use. I think some of ours are using DW right now ... but I've made my very best sites with VIM. That is the beauty of H:T. As for the other question, about multiple templates, you can either do as Kenny said and use includes (investigate options to ->new( ) for clues on how to really control these) or use a code construct like this : my $head = $self->load_tmpl("head1_tmpl.html"); my $body = $self->load_tmpl("login_tmpl.html"); my $foot = $self->load_tmpl("foot1_tmpl.html"); my $output = $head->output( ); $output .= $body->output( ); $output .= $foot->output( ); return $output; == this is from a CGI::Application ... 'load_tmpl( )' eventually gets around to calling the HTML::Template->new( ) method. I used to use includes, but no more. Thanks, Cory |
From: Kenny S. <ke...@jo...> - 2002-08-03 01:23:06
|
Hi Will, I _think_ what your asking is about including templates within your templates... and yes, you can. Using <TMPL_INCLUDE NAME=/path/to/file.tmpl> HTML::Template doesn't care about your HTML syntax, it only cares about your H::T syntax, so, yes you can span tables across your templates, and such. I do that with my headers and footers. In the header, I print the logo of the site and navbar, and then open a <td>... then in the footer I close that td and the rest of the table. So in my main template, I have something like: ------ policies.tmpl ------- <TMPL_INCLUDE NAME=header.tmpl> <!-- whatever HTML I want for this page --> <TMPL_INCLUDE NAME=footer.tmpl> ---------- end --------------- Kenny Smith JournalScape.com |
From: Will <sel...@ya...> - 2002-08-03 00:25:12
|
Greets Folks, Sorry... I forgot... have one more question... Suppose I want to use multiple templates in a document, then how would I do that? For instance, suppose I had something like this: use HTML::Template; my $bar = 'World'; my $template = HTML::Template->new(filename => 'body.tmpl'); $template->param(MESSAGE => $bar); print $template->output; and it's corresponding template file: <!-- body.tmpl --> <h1>Hello <TMPL_VAR NAME=MESSAGE></h1> But suppose I wanted to give this "Hello World" message a header and a footer... such that I would have header.tmpl and footer.tmpl... then what would I do? TIA, Will P.S. Also, can one nest tables in HTML::Template? I mean, within other templates? __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com |
From: Will <sel...@ya...> - 2002-08-02 23:50:53
|
Greets Folks, In just about all the CGI books I read they have some section on how to write forms. When I see this it kind of drives me nuts cause I can just design all my forms and elements in an HTML editor, like DreamWeaver... I cant tell if I am justified in feeling this way or not, but IMHO attractive forms can be a challenge to design, and it took me awhile to get the formatting right with them... Basically, I never try to set form tags into tables, but I will always set the form's elements inside a table inside a form tag... this prevents the table from becoming skewed by the form tag or its elements... Maybe I am exagerrating things here a bit, but I'd rather just stick to this method... It's simply easier to design a form in DreamWeaver... Now my question... what do you folks think? Am I being too stubborn here, or should I learn the CGI on form writing? Maybe it would just be easiest to design my forms in DW and then set them into H::T? Is this recommended? What are the pros and cons of this approach? Any help much appreciated. TIA, will __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com |
From: Jesse E. <je...@er...> - 2002-08-01 12:03:51
|
Hi All -- > The only way for you to use the param() method without qualifying it > with an object first is if you import it into your program like this: > > use CGI ':standard'; > > Then you could just say: > > my $name = param("name"); # no need of my $cgi = new CGI; > $t->param("name" => param("name")); > > However, I don't particularly advocate importing all the CGI methods > into your namespace. For one, it pollutes your namespace, and secondly, > it makes things very confusing when you have two methods of the same > name, one bound to an object and one not. > > HTML::Template does not export its methods to your code. You *must* > always use them bound to an object. Neither HTML::Template nor CGI::Application will export a param() method. In fact, exporting CGI.pm's param method via "use CGI ':standard'" is a common source of confusion and bugs. The exported method will stomp all over the other param() methods -- particularly in the case of CGI::Application where a param() method exists locally via inheritance. In general, I avoid exporting or importing symbols as much as possible. In the object-oriented world of Perl exporting is mostly an anachronism -- a throwback to Perl's procedural roots. FWIW, the param() methods in HTML::Template and CGI::Application were both intentionally made to function exactly as CGI.pm's method functions. The feeling was that users of the former two modules would already be familiar with the interface to CGI.pm's param() method. When you design an interface you have to do so with your users in mind. TTYL, -Jesse- -- Jesse Erlbaum The Erlbaum Group je...@er... Phone: 212-684-6161 Fax: 212-684-6226 |
From: Kenny P. <py...@ve...> - 2002-07-30 18:50:53
|
Andrew, Without being able to set a value in a template, you have to change backend scripts to enact this change, even though nothing in those templates needs to change. If there is a customer feedback script called feedback.cgi, your CGI programmer needs to care about the site layout and design to pass in a variable. You will run into similar problems all the time if you design your app using an MVC style. Does this help shed some light on why this functionality is desireable? It sounds like you are changing the functionality of the application when you make a change to the feedback template. A simple mail-form script would not need changed when you update the html form template if it is written correctly. If you are using a mail-form script and you have to update your "backend" then I suggest you re-write your mail script to be dynamic based on what is in the CGI object. If you are familiar with the associate feature in HTML::Template you will not have to worry about the way the form data is passed from form to form unless you have to act on the input. In that case, of course you would need to change the backend to work in the new way. Do you use CGI::Application? You do not need to worry about the layout of the template nor do you want to set values in the template. You have to break your paradigm. I highly suggest looking into CGI::App. It is a great way to use HTML::Template and would help you gain more control over your apps. Humbly, Andrew ---------------------------------------------------------------------- Andrew Ho http://www.tellme.com/ an...@te... Engineer in...@te... Voice 650-930-9062 Tellme Networks, Inc. 1-800-555-TELL Fax 650-930-9101 ---------------------------------------------------------------------- ------------------------------------------------------- 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 Thanks, Kenny Pyatt President Venzia www.venzia.com |
From: Andrew Ho <an...@te...> - 2002-07-30 07:02:36
|
Hello, YY><TMPL_DEF NAME="NAME" VALUE="value"> ST>I don't like this. Mixing display logic with setup of variables is a ST>very dangerous thing. KS>I don't even know what this is really useful for? If you are hard coding KS>the definition of a variable in your template, why can't you just hard KS>code that variable where you use it? I hacked in support for exactly this functionality using a filter, so let me explain why you can't do that. Pretend you have a header.tmpl that has several different tabs on it, where one is highlighted and the others are not highlighted. It is easiest to write this as a single HTML::Template template and have a bunch of <TMPL_IF>s based on a <TMPL_VAR>. That <TMPL_VAR>, say it's called "where", says where you are (like "aboutus" or "companynews" or whatever) in the site. Now, many templates include header.tmpl. The HTML::Template model encourages HTML designers to be separate from coders. Say the site layout changes, like, the tabs get changed around. About us and company news go under the same tab which is called "Company Buzz" or something. A whole lot of HTML needs to be rewritten, but all the backend scripts are the same. Without being able to set a value in a template, you have to change backend scripts to enact this change, even though nothing in those templates needs to change. If there is a customer feedback script called feedback.cgi, your CGI programmer needs to care about the site layout and design to pass in a variable. You will run into similar problems all the time if you design your app using an MVC style. Does this help shed some light on why this functionality is desireable? Humbly, Andrew ---------------------------------------------------------------------- Andrew Ho http://www.tellme.com/ an...@te... Engineer in...@te... Voice 650-930-9062 Tellme Networks, Inc. 1-800-555-TELL Fax 650-930-9101 ---------------------------------------------------------------------- |
From: Philip S T. <phi...@gm...> - 2002-07-29 04:57:14
|
On Sun, 28 Jul 2002, Will wrote: > Suppose from the html I have to parameters coming in: "name"="will" > and "age"="20"... when they are passed to a script running both > CGI.pm and HTML::Template... can I then just use them anyway I want > simply by invoking param("name") or param("age") anywhere in the > script...? Ok, here goes: use CGI; my $cgi = new CGI; my $name = $cgi->param("name"); # Note the $cgi-> before the param. It says that param is a method of # the CGI object named $cgi. use HTML::Template; my $t = new HTML::Template(filename => 'mytemplate.tmpl'); $t->param("name" => "Philip"); # Note the $t-> before param. It says that param is a method of the # HTML::Template object $t. # You can also do this, although there are better ways $t->param("name" => $cgi->param("name")); # which would transfer the CGI parameter name to the HTML::Template # object $t. The better way to do that would be: my $t = new HTML::Template(filename => 'mytemplate.tmpl', associate => $cgi); The only way for you to use the param() method without qualifying it with an object first is if you import it into your program like this: use CGI ':standard'; Then you could just say: my $name = param("name"); # no need of my $cgi = new CGI; $t->param("name" => param("name")); However, I don't particularly advocate importing all the CGI methods into your namespace. For one, it pollutes your namespace, and secondly, it makes things very confusing when you have two methods of the same name, one bound to an object and one not. HTML::Template does not export its methods to your code. You *must* always use them bound to an object. Philip |
From: Will <sel...@ya...> - 2002-07-29 01:01:24
|
Cory said---> This is a feature, trust me. CGI::Application, and many other modules all have param( ) methods. This (for one) allows them to communicate with each other, (for two) lets us remember only one interface to objects. --- Hmmm... well, does the use of this feature (polymorphism) mean that anytime a module supports a param() method all I have to do is something like the following: Suppose from the html I have to parameters coming in: "name"="will" and "age"="20"... when they are passed to a script running both CGI.pm and HTML::Template... can I then just use them anyway I want simply by invoking param("name") or param("age") anywhere in the script...? I hope this question makes sense, but it is helpful to know about polymorphism. It should help to clear things up once I grasp it. TFTH, =) will __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com |
From: Philip S T. <phi...@gm...> - 2002-07-28 20:01:34
|
Sometime on Jul 28, Cory Trese assembled some asciibets to say: > This is a feature, trust me. CGI::Application, and many other > modules all have param( ) methods. This (for one) allows them to A feature called polymorphism. -- Regarding astral projection, Woody Allen once wrote, "This is not a bad way to travel, although there is usually a half-hour wait for luggage." |
From: Cory T. <ct...@on...> - 2002-07-28 18:42:32
|
This is a feature, trust me. CGI::Application, and many other modules all have param( ) methods. This (for one) allows them to communicate with each other, (for two) lets us remember only one interface to objects. To avoid confusion, name your objects well in your code. Maybe it is just us but I never noticed / heard about anyone being confused about this ... maybe it is just a getting used to thing. However, you can (to a certain extent) avoid using this method between H::T and CGI.pm with the 'associate=>' switch for H::T new() method to simply attach the two, instructing H::T to find any unset vars in the CGI.pm object. For me, this is the reason why I have built more modules with the same interface (param()) ... this association thing is a really handy way to control your H::T objects in an abstract manner. -- Cory > -----Original Message----- > From: htm...@li... > [mailto:htm...@li...]On Behalf Of > Will > Sent: Sunday, July 28, 2002 2:22 PM > To: HTML Template > Subject: [htmltmpl] Confusion > > > As I have been learning HTML::Template and CGI.pm... > I found something a bit confusing, so maybe you good > folks can help me clear it up... > > Both CGI.pm and HTML::Template have param() > functions... so I am concerned about confusing the > two... > > Any advice? > > Thanks, > > Will > > __________________________________________________ > Do You Yahoo!? > Yahoo! Health - Feel better, live better > http://health.yahoo.com > > > ------------------------------------------------------- > 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: Will <sel...@ya...> - 2002-07-28 18:22:28
|
As I have been learning HTML::Template and CGI.pm... I found something a bit confusing, so maybe you good folks can help me clear it up... Both CGI.pm and HTML::Template have param() functions... so I am concerned about confusing the two... Any advice? Thanks, Will __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com |
From: Yunliang Yu <yu...@ma...> - 2002-07-27 03:35:58
|
Thanks to Sam and this list's ideas and discussions, I rewrote most of the patches and it's optimized to be about as fast as the original HTML::Template module. Please see the URL http://www.math.duke.edu/~yu/Template/ for the latest changes and patches. 1. The notation for accessing outside variables was changed from "__name" to "::name", which adds no more restrictions on the names that you can use, at least according to the FAQ. 2. Extensive checks are done to eval()'ed expressions to make sure they are secure. 3. An example use of TMPL_DEF: <TMPL_DEF NAME="SQLCMD" VALUE="select * from News where Date=Now() and Source <> 'XYZ'"> <TMPL_DEF NAME="SQLREC" VALUE="news"> ......Today's Headlines: <TMPL_LOOP NAME="news"> <li><TMPL_VAR NAME="Source">: <TMPL_VAR NAME="Title">....... </TMPL_LOOP> The perl script queries the SQL command, runs it and stuffs the records into the given variable. It's not easier to do this with TMPL_INCLUDE or query() alone. Imagine that you have 1 webmaster, 2 programmers, 3 DBAs, 40 designers and 5000 clients who all want different data... Well, it's time for me to move on to other projects. But I'll maintain the URL as long as I see any bugs or good ideas. Thanks. -yu |
From: Philip S T. <phi...@gm...> - 2002-07-25 18:10:34
|
Sometime Today, Mark Mertel assembled some asciibets to say: > <tmpl_obj object="Object" var="id"> > <tmpl_obj object="Object" var="name"> <tmpl_var name="Object.id"> <tmpl_var name="Object.name"> > and in the .pl - > > my $Object = Object->new; > > $Object->{id} = 23; > $Object->{name} = "this is an object"; for (@keys %$Object) { $template->param("Object.$_" => $Object->{$_}); } -- To communicate is the beginning of understanding. -- AT&T |
From: Mark M. <mm...@ol...> - 2002-07-25 17:35:26
|
Hey, has anyone doing something like this - <tmpl_obj object="Object" var="id"> <tmpl_obj object="Object" var="name"> and in the .pl - my $Object = Object->new; $Object->{id} = 23; $Object->{name} = "this is an object"; my $template = HTML::Template->new(filename => "ErrorPage.tmpl", associate => $cgi, die_on_bad_params => 0); $template->param(object => $Object); sure would make some of my stuff cleaner if i could pass in a single object instead of arguments for each parameter/attribute. -- Mark Mertel mm...@ol... Phone: (360) 344-3113 FAX: (360) 344-3553 Cell: (206) 409-2018 |
From: Sam T. <sa...@tr...> - 2002-07-25 17:00:34
|
On Thu, 25 Jul 2002, David Kaufman wrote: > i don't like having a complex expression in the value of an attribute called > "name", either. if the patch really improves expression evaluation speed, > maybe it should be resubmitted as a patch for HTML::Template::Expr? since > we who don't use template expressions now can continue to simply not use > HTML::Template::Expr, and get the best performance of all :-) That would be one way to go, but I'll admit I'm hesitent. I went a long way to avoid eval()ing Perl code in HTML::Template:Expr. Maybe that was a mistake but I think I had some good reasons (security, speed, memory usage). > dangerous!, Sam? :-) might it melt the browser or burn the users' fingers? > heheh. seriously, though. systems evolve, and programs change. if an html > editor who maintains templates can "hard-code" or "override" a variable > value in a template in 30 seconds, to alter it in a way that would normally > require calling in the original programmer to change perl code, the only > "danger" i see is the danger that, by giving the "users" of a system more > control over (and therefore more responsibility for) the system, the > programmers (us!) might be given LESS control, responsibility, and thus, pay > :-) You're right - I don't see HTML designers as "users" of the module in the same way that Perl programmers are. I see them as working in an entirely different way - providing formatting for data provided by the Perl programmer. The system, by design, doesn't allow the HTML designer to reconfigure the data structures coming from Perl. This is the price we pay for not having to work with HTML - we do have to work with the data! In my perfect fantasy world each side has its domain, Perl and HTML, and neither should be allowed undo influence on the other. > by adding __count__ (and <tmpl default> and <tmpl_def>), i think we work > toward making good on those claims, empowering HTML designers to do as > much as possible without needing to re-hire us to alter the code. I never made those claims. I see HTML::Template as delivering a collaborative environment between Perl coders and HTML designers. I never envisioned a system where either could "engineered out" at any stage of the development. -sam |