html-template-users Mailing List for HTML::Template (Page 55)
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: C H. <hag...@ep...> - 2004-04-13 14:38:51
|
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 |
From: Jeff C. <oka...@po...> - 2004-04-13 11:44:07
|
Hi. I'm having problems with scalarref. I get the following error: ### HTML::Template Debug ### In _parse: 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. Here's my template: <TMPL_LOOP NAME=EMPLOYEE_INFO> Name: <TMPL_VAR NAME=NAME> <br> Job: <TMPL_VAR NAME=JOB> <p> </TMPL_LOOP> Here's my code: #!/usr/bin/perl use strict; use warnings; use HTML::Template; my $tmpl; $tmpl = &get_template($tmpl); $tmpl = &populate_template($tmpl); sub get_template { my $file = "/tmp/page1.tmpl"; open (TMPL, $file) or die "Failed to open template '$file': $!"; # Slurp file into scalar my $html = join ('', <TMPL>); close (TMPL) or warn "Failed to close template '$file': $!"; return $html; } sub populate_template { my $html = shift; my $template = HTML::Template->new( scalarref => \$html, option => 'value', debug => 1 ); return $template->output; } # end code The template works fine if I use filename => "/tmp/page1.tmpl" instead of scalarref :/ Any ideas? THANKS ___________________________________________________ Take your business online with Officemaster. Sign up for a free trial today! http://www.officemaster.net |
From: Andreas J. <And...@t-...> - 2004-04-11 22:59:43
|
Ich werde ab 09.04.2004 nicht im B=FCro sein. Ich kehre zur=FCck am 19.04.2004. Sehr geehrte Damen und Herren, Aus diesem Grund werde Ihre Nachricht erst nach meiner R=FCckkehr beant= worten k=F6nnen. Ihre Nachricht wird nicht weitergeleitet. Freundliche Gr=FC=DFe Dipl.Ing. Andreas Jablonowski T-Systems CSS GmbH Leiter Web & Knowledge Management Solutions Hausadresse: Roermonder Str. 615, 52072 Aachen Postanschrift: Postfach 10 06 55, 52006 Aachen Telefon: (0241) 93 79-499 Telefax: (0241) 93 79-619 E-Mail: And...@t-... Internet: http://www.t-systems.de= |
From: Sam T. <sa...@tr...> - 2004-04-08 18:38:20
|
Krang v1.015 in now available. Changes in this release: - Added support for Gentoo Linux, Fedora Core and FreeBSD. - Upgraded Apache and mod_perl to their latest releases. - Fixed numerous bugs and portability problems. - Improved documentation. Detailed change-log here: http://krang.sf.net/docs/changelog.html Krang is an Open Source web-publisher / content-management system designed for large-scale magazine-style websites. It is a 100% Perl application using Apache/mod_perl and MySQL, as well as numerous CPAN modules. Krang provides a powerful and easy to use story and media editing environment for magazine editors, as well as a complete template development environment for web designers. On the back-end, Perl programmers can customize Krang to control the data entered in the story editor and add code to drive the templates to build output. Krang can be enhanced with add-ons containing new skins and other new features. Krang easily handles large data sets and can manage multiple websites in a single installation. For more information about Krang, visit the Krang website: http://krang.sourceforge.net/ There you can download Krang, view screenshots, read documentation, join our mailing-lists and access the CVS tree. - the Krang team |
From: Mathew R. <mat...@re...> - 2004-04-06 00:10:10
|
> I thought this problem was solved with judicious use of filters. There = > are enough posts on this in the archives. Am I missing something here? = > Or are folks simply averse to using filters? As others have stated - sometimes filters can be used to solve the = problem; in other cases, using a TMPL_VAR as part of the TMPL_INCLUDE is = the simplest solution that presents itself. Mathew |
From: Puneet K. <pk...@ei...> - 2004-04-05 23:41:21
|
On Apr 5, 2004, at 2:18 PM, Eivind Hestnes wrote: > Hi, > > Short and to the point. > > 1. I'm using this script to dump information from a database (and it > works, > yes :). > > dump.pl > ----------------------------------------------------------------- > #!/usr/bin/perl > > .. > > sub db_connect { > > my ($result); > > $result = DBI->connect( > "DBI:$DBType:database=$DBName;host=$DBHost", > "$DBUser", "$DBPass", { 'RaiseError' => 0 } ) || &error("Unable to > connect to database"); > > return $result; > > } > > sub db_query { > > my ($result, $query); > > $query = $_[0]; > > $result = &db_connect->prepare($query) || &error("Unable to query > the > database"); > $result->execute(); > > return $result; > > } > > # outer loop > my $query1 = &db_query("SELECT id, title FROM sections"); > while (my $rows1 = $query1->fetchrow_hashref()) { > print "Section: " . $rows1->{title}."\n"; > > my $sectionid = $rows1->{id}; > > # inner loop > my $query2 = &db_query("SELECT title FROM pages WHERE sectionid = > $sectionid"); > while (my $rows2 = $query2->fetchrow_hashref()) { > print "-> Page: " . $rows2->{title}."\n"; > } > > } > ----------------------------------------------------------------- > > 2. Since I have started using HTML::Template on my webpage, I have to > port > this script to get use of a template. > The template looks something like this: > > dump.html > ----------------------------------------------------------------- > <TMPL_LOOP NAME="SECTIONS"> > Section: <TMPL_VAR NAME="TITLE"><br> > <TMPL_LOOP NAME="PAGES"> > -> Page: <TMPL_VAR NAME="TITLE"><br> > </TMPL_LOOP> > </TMPL_LOOP> > > 3. I have tried to make a new script for HTML::Template, but I can't > get the > script working with the template because of the outer/inner loop. > > you are likely going to get a lot of replies. I will just point out a few things -- a TMPL_LOOP is a ref to an array of hashes, where each hash is a key,value pair of fieldname and fieldvalue. The fetchall_arrayref({}) function conveniently does exactly that for you. So, call fetchall_arrayref({}) and pass the result directly to TMPL_LOOP like so -- sub db_query { my ($sql) = @_; my $sth = $dbh->prepare(qq{$sql}); $sth->execute; return $sth->fetchall_arrayref({}); } my $t->param(SECTIONS => &db_query("SELECT id, title FROM sections")); Now, what you are trying to do is build an internal loop of pages for every section. You can do it several different ways, but I prefer to do the db query in one shot using a JOIN as in SELECT s.id, s.title, p.title FROM sections s INNER JOIN pages p ON s.id = p.sectionid WHERE s.id = $sid This way I get all the results in one shot and then I group them in Perl using any one of the several methods discussed earlier in these archives. Search for "normalize" and you might find a complete, working code fragment posted by me a few months ago. The advantage of this approach is that you have to run the db query only once instead of once for every sectionid. Once you have the results, working with arrays and hashes in Perl is pretty much at the speed of the machine, aka, very fast. __END__ A few stylistic comments, fwiw -- In db_connect you don't need to declare $result separately and return it separately. You can do the entire thing on one line without decreasing readability -- sub db_connect { my $dbh = DBI->connect( "DBI:$DBType:database=$DBName;host=$DBHost", "$DBUser", "$DBPass", { 'RaiseError' => 0 } ) || &error("Unable to connect to database"); } When using DBI, I tend to use the handle names that Tim Bunce uses. That makes the intent very clear to me, to other readers of my code, and when comparing it with examples in DBI.pod. So, $dbh, $sth, etc. And, finally, I would probably alias the id and title fields in the database so their purpose it clear as -- SELECT s.id AS sectionid, s.title as sectiontitle, p.title as pagetitle FROM sections s INNER JOIN pages p ON s.id = p.sectionid WHERE s.id = $sid |
From: Eivind H. <eiv...@st...> - 2004-04-05 22:10:09
|
Hi, Short and to the point. 1. I'm using this script to dump information from a database (and it works, yes :). dump.pl ----------------------------------------------------------------- #!/usr/bin/perl use CGI qw/:standard :html3/; use CGI::Carp qw(fatalsToBrowser); use DBI; use DBD::mysql; my $DBName = "test"; my $DBHost = "localhost"; my $DBUser = "test"; my $DBPass = "dev"; my $DBType = "mysql"; my $DBPort = "3306"; sub db_connect { my ($result); $result = DBI->connect( "DBI:$DBType:database=$DBName;host=$DBHost", "$DBUser", "$DBPass", { 'RaiseError' => 0 } ) || &error("Unable to connect to database"); return $result; } sub db_query { my ($result, $query); $query = $_[0]; $result = &db_connect->prepare($query) || &error("Unable to query the database"); $result->execute(); return $result; } # outer loop my $query1 = &db_query("SELECT id, title FROM sections"); while (my $rows1 = $query1->fetchrow_hashref()) { print "Section: " . $rows1->{title}."\n"; my $sectionid = $rows1->{id}; # inner loop my $query2 = &db_query("SELECT title FROM pages WHERE sectionid = $sectionid"); while (my $rows2 = $query2->fetchrow_hashref()) { print "-> Page: " . $rows2->{title}."\n"; } } ----------------------------------------------------------------- 2. Since I have started using HTML::Template on my webpage, I have to port this script to get use of a template. The template looks something like this: dump.html ----------------------------------------------------------------- <TMPL_LOOP NAME="SECTIONS"> Section: <TMPL_VAR NAME="TITLE"><br> <TMPL_LOOP NAME="PAGES"> -> Page: <TMPL_VAR NAME="TITLE"><br> </TMPL_LOOP> </TMPL_LOOP> 3. I have tried to make a new script for HTML::Template, but I can't get the script working with the template because of the outer/inner loop. Somebody out there with a solution? :-) Regards, Eivind Hestnes |
From: Cees H. <ce...@si...> - 2004-04-05 19:17:40
|
Jason Yates wrote: > Puneet Kishor wrote: > >> I thought this problem was solved with judicious use of filters. There >> are enough posts on this in the archives. Am I missing something here? >> Or are folks simply averse to using filters? > > In my case, I pull a id from a database and then load the template with > that id. For instance, I'll pull id 5 and the template will be named > 5.tmpl. There is no ability with filters to pass that id to the filter > function. So in my case, I'd have to create another CGI object grab > relevents paramaters, load the DBI object reconnect to the database, > and query the database for the id. Filters just won't work well for > what I'm trying to do. Especially if there are a number of includes, > the above process could be run 4-5 times. It would be extremely slow. You can use variables in your filters through the use of a closure. So you don't have to create a new CGI object and database connection... Here is some psuedo code to explain how to do it: my $dbh = ... Get DB handle ... my $template = HTML::Template->new( filename => 'zap.tmpl', filter => sub { my $text_ref = shift; my $sth = $dbh->prepare('... SQL ...'); ... }, }); the anonymous subroutine will act as a closure with respect to $dbi. See the perldocs for 'perlsub' for more on closures. But there is a problem with using filters that alter the template dynamically. The caching mechanism fails to take into consideration anything that is done with the filters. In other words, after the first time your filter gets run, the resulting template will be cached, and the filter will not be executed again the next time the template is called (ie on the next request). So if your filters change dynamically based on some parameter, then you must turn off caching. Check the archives for more discussions on this. Cees |
From: Jason Y. <ja...@co...> - 2004-04-05 17:45:13
|
Puneet Kishor wrote: > I thought this problem was solved with judicious use of filters. There > are enough posts on this in the archives. Am I missing something here? > Or are folks simply averse to using filters? In my case, I pull a id from a database and then load the template with that id. For instance, I'll pull id 5 and the template will be named 5.tmpl. There is no ability with filters to pass that id to the filter function. So in my case, I'd have to create another CGI object grab relevents paramaters, load the DBI object reconnect to the database, and query the database for the id. Filters just won't work well for what I'm trying to do. Especially if there are a number of includes, the above process could be run 4-5 times. It would be extremely slow. |
From: Puneet K. <pk...@ei...> - 2004-04-05 13:27:48
|
On Apr 4, 2004, at 11:03 PM, Mathew Robertson wrote: > This is my local stable version of H::T (and releated modules). This > version has lot of changes, but you will want to use the > 'recursive_templates' argument => set it to the depth that you will > allow recursion. > > CAVEAT: Allowing recursive TMPL_INCLUDE's seriously breaks your > ability to debug bad templates. This is becuase H::T will die with a > message saying something like "TMPL_INCLUDE blah", which makes it kind > of hard to figure out if the current H::T output contains a valid > TMPL_INCLUDE, or an error message. In the future I hope to solve this > problem... > > Hope this helps, > Mathew > > > > ----- Original Message ----- > From: "Jason Yates" <ja...@co...> > To: <htm...@li...> > Sent: Monday, April 05, 2004 12:49 PM > Subject: [htmltmpl] Variable in TMPL_INCLUDE > > >> Searching the mailing list, a few people have mentioned a patch for >> allowing variable filenames for the TMPL_INCLUDE tag. Something like >> this: >> >> $t->param(FILE => 'some_file.tmpl'); >> >> <TMPL_INCLUDE NAME="FILE"> >> >> I'm currently getting around this problem by loading two templates and >> outputing one into a variable of another. It works but it is kind of >> a >> hack. I'm wondering if anyone's made a patch for this feature. If >> not, I'd probably hack one out. >> >> I thought this problem was solved with judicious use of filters. There are enough posts on this in the archives. Am I missing something here? Or are folks simply averse to using filters? |
From: Mathew R. <mat...@re...> - 2004-04-05 04:03:38
|
This is my local stable version of H::T (and releated modules). This = version has lot of changes, but you will want to use the = 'recursive_templates' argument =3D> set it to the depth that you will = allow recursion. CAVEAT: Allowing recursive TMPL_INCLUDE's seriously breaks your ability = to debug bad templates. This is becuase H::T will die with a message = saying something like "TMPL_INCLUDE blah", which makes it kind of hard = to figure out if the current H::T output contains a valid TMPL_INCLUDE, = or an error message. In the future I hope to solve this problem... Hope this helps, Mathew ----- Original Message -----=20 From: "Jason Yates" <ja...@co...> To: <htm...@li...> Sent: Monday, April 05, 2004 12:49 PM Subject: [htmltmpl] Variable in TMPL_INCLUDE > Searching the mailing list, a few people have mentioned a patch for=20 > allowing variable filenames for the TMPL_INCLUDE tag. Something like = this: >=20 > $t->param(FILE =3D> 'some_file.tmpl'); >=20 > <TMPL_INCLUDE NAME=3D"FILE"> >=20 > I'm currently getting around this problem by loading two templates and = > outputing one into a variable of another. It works but it is kind of = a=20 > hack. I'm wondering if anyone's made a patch for this feature. If=20 > not, I'd probably hack one out. >=20 >=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: Jason Y. <ja...@co...> - 2004-04-05 02:48:23
|
Searching the mailing list, a few people have mentioned a patch for allowing variable filenames for the TMPL_INCLUDE tag. Something like this: $t->param(FILE => 'some_file.tmpl'); <TMPL_INCLUDE NAME="FILE"> I'm currently getting around this problem by loading two templates and outputing one into a variable of another. It works but it is kind of a hack. I'm wondering if anyone's made a patch for this feature. If not, I'd probably hack one out. |
From: Sam T. <sa...@tr...> - 2004-03-31 20:03:22
|
Krang v1.014, the first public release, is now available. Krang is an Open Source web-publisher / content-management system designed for large-scale magazine-style websites. It is a 100% Perl application using Apache/mod_perl and MySQL, as well as numerous CPAN modules. Krang provides a powerful and easy to use story and media editing environment for magazine editors, as well as a complete template development environment for web designers. On the back-end, Perl programmers can customize Krang to control the data entered in the story editor and add code to drive the templates to build output. Krang can be enhanced with add-ons containing new skins and other new features. Krang easily handles large data sets and can manage multiple websites in a single installation. For more information about Krang, visit the Krang website: http://krang.sourceforge.net/ There you can download Krang, view screenshots, read documentation, join our mailing-lists and access the CVS tree. - the Krang team PS: Krang uses HTML::Template for both its user-interface and output templating. If you're in need of a large-scale web publishing platform with HTML::Template support, look no further! |
From: Mathew R. <mat...@re...> - 2004-03-29 23:03:58
|
yep.... do this: <TMPL_IF EXPR=3D"((event_id ne '915') and (event_id ne '917')) and = ((event_id ne '997') ...)"> Stuff </TMPL_IF> ... notice that we group two pairs of expressions using the brackets.. Mathew ----- Original Message -----=20 From: "Chad Phillips" <gph...@ka...> To: <htm...@li...> Sent: Tuesday, March 30, 2004 8:54 AM Subject: [htmltmpl] how many expressions allowed? > I am having a problem with EXPR. Is there a limit to how man ANDs you = can > have? >=20 > This: > <TMPL_IF EXPR=3D"(event_id ne '915') and (event_id ne '917') and = (event_id > ne '997') "> > Stuff > </TMPL_IF> >=20 > throws this errer: > HTML::Template::Expr : Unable to parse expression: >=20 > but >=20 > <TMPL_IF EXPR=3D"(event_id ne '915') and (event_id ne '917')"> > works just fine. >=20 > any thoughts? >=20 > thanks > chad >=20 >=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: Chad P. <gph...@ka...> - 2004-03-29 22:55:04
|
I am having a problem with EXPR. Is there a limit to how man ANDs you can have? This: <TMPL_IF EXPR="(event_id ne '915') and (event_id ne '917') and (event_id ne '997') "> Stuff </TMPL_IF> throws this errer: HTML::Template::Expr : Unable to parse expression: but <TMPL_IF EXPR="(event_id ne '915') and (event_id ne '917')"> works just fine. any thoughts? thanks chad |
From: Adrian G. <ad...@lo...> - 2004-03-29 11:39:08
|
At 17:03 29.03.2004 +1000, simran wrote: >Have a look at help on "filters" in the HTML::Template documentation. >They usually come very handy for this type of stuff... You're right, that's an even better solution. Thanks! Adrian Grigore -- Adrian Grigore ad...@lo... Lobstersoft - Fun Brain-Bending Games For All Ages http://www.lobstersoft.com Member of the Association of Shareware Professionals |
From: Adrian G. <ad...@lo...> - 2004-03-29 11:25:20
|
Thanks, Bill! Seems to be made exactly for what I need :-) --Adrian Adrian Grigore -- Adrian Grigore ad...@lo... Lobstersoft - Fun Brain-Bending Games For All Ages http://www.lobstersoft.com Member of the Association of Shareware Professionals |
From: simran <sim...@re...> - 2004-03-29 06:59:33
|
Have a look at help on "filters" in the HTML::Template documentation. They usually come very handy for this type of stuff... On Mon, 2004-03-29 at 14:32, Bill Nixon wrote: > How about using another instance of HTML::Template within your code to generate the upselling HTML text and assign the Template > output to a TMPL_VAR. > > Something like: > > # generate the upsell HTML > my $upsell_template = HTML::Template->new(filename => 'test.tmpl'); > ... > my $upsell_html = $upsell_template->output; > > # handle the main template > my $main_template = HTML::Template->new ... > ... > # include the upsell HTML as a TMPL_VAR > $template->param(UPSELL_HTML => $upsell_html); > > Then, in your main HTML file, just use a normal <TMPL_VAR name="UPSELL_HTML"> to include the HTML where you want it. > > ----- Original Message ----- > From: "Adrian Grigore" <ad...@lo...> > To: <htm...@li...> > Sent: Sunday, March 28, 2004 9:04 AM > Subject: [htmltmpl] TMPL_INCLUDE with variable name? > > > > Hi, > > > > I would like to create a template representing a sales checkout page which > > is supposed to have different upselling items on the bottom, depending > > which items are currently in the shopping basket. I would like to include > > the HTML tag to the upselling item with TMPL_INCLUDE, but the problem is > > that the name of the template that should be included is dynamic, so I > > cannot write that as fixed string into the shopping basked template. > > > > The problem description above is probably too confusing, so here's an > > example of what I am trying to do. I have this template which the contents > > of the user's shopping basket plus an upselling item: > > > > some code for displaying shopping cart.... > > <!-- now include the template that includes the upselling item --> > > <TMPL_INCLUDE NAME="myupsellingitem1.tmpl"> > > some more code for the page footer. > > > > Now, this works fine if I have only one upselling item. But If I have 2 of > > them and only the perl script knows which one should be displayed I would > > need I TMPL_INCLUDE that works with a name refers to the name of a TMPL_VAR > > of the same context. I would need something like this: > > > > some code for displaying shopping cart.... > > <!-- now include the template that includes the upselling item --> > > <TMPL_INCLUDE NAME=UPSELLING_TEMPLATE_FILENAME> > > some more code for the page footer. > > > > and of course I would need to have something like > > $Template->param(UPSELLING_TEMPLATE_FILENAME => 'myupsellingitem1.tmpl'); > > in my template. > > > > Unfortunately this is currently not possible in HTML::Template. I could > > think of loading the template via HTTP and using server side includes or > > php to do the job, but that would be an ugly solution. It would also be > > possible to "filter" the output of one template and use it as input for the > > next, but that would be quite messy too. Is there any clean way to do this? > > > > Thanks, > > > > Adrian Grigore > > > > -- > > Adrian Grigore > > ad...@lo... > > Lobstersoft - Fun Brain-Bending Games For All Ages > > http://www.lobstersoft.com > > Member of the Association of Shareware Professionals > > > > > > > > ------------------------------------------------------- > > 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 > > > > ------------------------------------------------------- > 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 |
From: Bill N. <bn...@co...> - 2004-03-29 04:33:12
|
How about using another instance of HTML::Template within your code to generate the upselling HTML text and assign the Template output to a TMPL_VAR. Something like: # generate the upsell HTML my $upsell_template = HTML::Template->new(filename => 'test.tmpl'); ... my $upsell_html = $upsell_template->output; # handle the main template my $main_template = HTML::Template->new ... ... # include the upsell HTML as a TMPL_VAR $template->param(UPSELL_HTML => $upsell_html); Then, in your main HTML file, just use a normal <TMPL_VAR name="UPSELL_HTML"> to include the HTML where you want it. ----- Original Message ----- From: "Adrian Grigore" <ad...@lo...> To: <htm...@li...> Sent: Sunday, March 28, 2004 9:04 AM Subject: [htmltmpl] TMPL_INCLUDE with variable name? > Hi, > > I would like to create a template representing a sales checkout page which > is supposed to have different upselling items on the bottom, depending > which items are currently in the shopping basket. I would like to include > the HTML tag to the upselling item with TMPL_INCLUDE, but the problem is > that the name of the template that should be included is dynamic, so I > cannot write that as fixed string into the shopping basked template. > > The problem description above is probably too confusing, so here's an > example of what I am trying to do. I have this template which the contents > of the user's shopping basket plus an upselling item: > > some code for displaying shopping cart.... > <!-- now include the template that includes the upselling item --> > <TMPL_INCLUDE NAME="myupsellingitem1.tmpl"> > some more code for the page footer. > > Now, this works fine if I have only one upselling item. But If I have 2 of > them and only the perl script knows which one should be displayed I would > need I TMPL_INCLUDE that works with a name refers to the name of a TMPL_VAR > of the same context. I would need something like this: > > some code for displaying shopping cart.... > <!-- now include the template that includes the upselling item --> > <TMPL_INCLUDE NAME=UPSELLING_TEMPLATE_FILENAME> > some more code for the page footer. > > and of course I would need to have something like > $Template->param(UPSELLING_TEMPLATE_FILENAME => 'myupsellingitem1.tmpl'); > in my template. > > Unfortunately this is currently not possible in HTML::Template. I could > think of loading the template via HTTP and using server side includes or > php to do the job, but that would be an ugly solution. It would also be > possible to "filter" the output of one template and use it as input for the > next, but that would be quite messy too. Is there any clean way to do this? > > Thanks, > > Adrian Grigore > > -- > Adrian Grigore > ad...@lo... > Lobstersoft - Fun Brain-Bending Games For All Ages > http://www.lobstersoft.com > Member of the Association of Shareware Professionals > > > > ------------------------------------------------------- > 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 |
From: Adrian G. <ad...@lo...> - 2004-03-28 14:04:40
|
Hi, I would like to create a template representing a sales checkout page which is supposed to have different upselling items on the bottom, depending which items are currently in the shopping basket. I would like to include the HTML tag to the upselling item with TMPL_INCLUDE, but the problem is that the name of the template that should be included is dynamic, so I cannot write that as fixed string into the shopping basked template. The problem description above is probably too confusing, so here's an example of what I am trying to do. I have this template which the contents of the user's shopping basket plus an upselling item: some code for displaying shopping cart.... <!-- now include the template that includes the upselling item --> <TMPL_INCLUDE NAME="myupsellingitem1.tmpl"> some more code for the page footer. Now, this works fine if I have only one upselling item. But If I have 2 of them and only the perl script knows which one should be displayed I would need I TMPL_INCLUDE that works with a name refers to the name of a TMPL_VAR of the same context. I would need something like this: some code for displaying shopping cart.... <!-- now include the template that includes the upselling item --> <TMPL_INCLUDE NAME=UPSELLING_TEMPLATE_FILENAME> some more code for the page footer. and of course I would need to have something like $Template->param(UPSELLING_TEMPLATE_FILENAME => 'myupsellingitem1.tmpl'); in my template. Unfortunately this is currently not possible in HTML::Template. I could think of loading the template via HTTP and using server side includes or php to do the job, but that would be an ugly solution. It would also be possible to "filter" the output of one template and use it as input for the next, but that would be quite messy too. Is there any clean way to do this? Thanks, Adrian Grigore -- Adrian Grigore ad...@lo... Lobstersoft - Fun Brain-Bending Games For All Ages http://www.lobstersoft.com Member of the Association of Shareware Professionals |
From: Puneet K. <pk...@ei...> - 2004-03-26 21:30:28
|
Cees Hek wrote: > Puneet Kishor wrote: > >> The problem is thus -- I am storing only the identifying info and a >> descriptive text. But the AofH in the Session file is showing >> additional info that looks suspiciously like the loop_context_vars. >> Here is an excerpt from my Session file -- >> >> "rolodex" => [{"ROLODEXVAL" => 3330,"__last__" => 0,"ROLODEXTEXT" => >> "Puneet Kishor (My Org, Inc.)","__counter__" => undef,"__first__" => >> 0,"__odd__" => 0,"__inner__" => 0}], > > > This is probably because you are passing a reference to a data structure > to both CGI::Session and HTML::Template. In other words they both get > the exact in memory data structure. HTML::Template is adding things to > the hashes that are stored in the array ref, and CGI::Session doesn't > save it's parameters to the session until it goes out of scope (probably > at the end of the request) so it sees the changes that HTML::Template > made to the data. > > There are a couple of things you can do to solve it. > > - Don't pass the same data structure to both CGI::Session and > HTML::Template. Make a copy of the data before passing it by > dereferencing the data (see the dclone() method in the Storable module > for copying complex data structures if you have a deep data structure). > > - Or you can make CGI::Session save it's data right away by making it go > out of scope, or calling close or flush to sync the data to the session > store. > > Although HTML::Template is causing this problem, I don't think you cna > call it a bug. Although many modules will make a copy of the data that > is passed in if they intend to make any changes, that can be very > expensive if there is a lot of data (which there tends to be when > dealing with templates). > That explains it. You hit it right on the nose, Cees. It is indeed happening because I am sending the same ref to the AofH. Thanks much for you advice as I now know how to solve it. Puneet. |
From: Cees H. <ce...@si...> - 2004-03-26 21:27:06
|
Puneet Kishor wrote: > The problem is thus -- I am storing only the identifying info and a > descriptive text. But the AofH in the Session file is showing additional > info that looks suspiciously like the loop_context_vars. Here is an > excerpt from my Session file -- > > "rolodex" => [{"ROLODEXVAL" => 3330,"__last__" => 0,"ROLODEXTEXT" => > "Puneet Kishor (My Org, Inc.)","__counter__" => undef,"__first__" => > 0,"__odd__" => 0,"__inner__" => 0}], This is probably because you are passing a reference to a data structure to both CGI::Session and HTML::Template. In other words they both get the exact in memory data structure. HTML::Template is adding things to the hashes that are stored in the array ref, and CGI::Session doesn't save it's parameters to the session until it goes out of scope (probably at the end of the request) so it sees the changes that HTML::Template made to the data. There are a couple of things you can do to solve it. - Don't pass the same data structure to both CGI::Session and HTML::Template. Make a copy of the data before passing it by dereferencing the data (see the dclone() method in the Storable module for copying complex data structures if you have a deep data structure). - Or you can make CGI::Session save it's data right away by making it go out of scope, or calling close or flush to sync the data to the session store. Although HTML::Template is causing this problem, I don't think you cna call it a bug. Although many modules will make a copy of the data that is passed in if they intend to make any changes, that can be very expensive if there is a lot of data (which there tends to be when dealing with templates). Cheers, Cees |
From: Puneet K. <pk...@ei...> - 2004-03-26 21:20:08
|
m.s...@gm... wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi Puneet, hi list > > You are on the right list, it's an H::T issue and has nothing to with > CGI::Session. I discovered the same some weeks ago. > > It seems than H::T can contaminate your data structure - for the sake > of speed, no copying is done in H::T. If it really bothers you, you > might consider using a clone package (try > http://search.cpan.org/search?query=clone&mode=all) to first copy > your data structure, then let H::T work on the clone and discard it > after displaying. > Markus, Thanks for the reply. This is very informative, and I will follow your suggestion (and hope the H-T developers will consider this as a problem to be solved). But, my question is -- where on earth did I let H-T "contaminate" my AofH? I am hand-crafting my own AofH -- # A hash to hold the current rolodex entry my %rolodexentry = ( ROLODEXVAL => $rolodexval, ROLODEXTEXT => $rolodextext ); # Add the current rolodexentry to the existing rolodex push(@rolodex, \%rolodexentry); Where, o, where is H-T even touching all this? Thanks, Puneet. |
From: <m.s...@gm...> - 2004-03-26 21:15:39
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Puneet, hi list You are on the right list, it's an H::T issue and has nothing to with CGI::Session. I discovered the same some weeks ago. It seems than H::T can contaminate your data structure - for the sake of speed, no copying is done in H::T. If it really bothers you, you might consider using a clone package (try http://search.cpan.org/search?query=clone&mode=all) to first copy your data structure, then let H::T work on the clone and discard it after displaying. Kind regards - Markus -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.6 and Gnu Privacy Guard <http://www.gnupg.org/> iD8DBQFAZJ1txxUzQSse11ARAt0yAJ40Ttc/pymQYuzsYuSi/yHesvoK8QCeOEe6 OuQqmIfNBzj6FhPNStx9+TU= =1d+T -----END PGP SIGNATURE----- |
From: Puneet K. <pk...@ei...> - 2004-03-26 20:24:43
|
Two apologies -- 1. goofy subject line, because I couldn't think of a concise, precise description. 2. might be considered OT, but it seems H-T is a part of this strangeness (and there seems to be no active mailing list for CGI-Session), so... I am using CGI-Session to write to a session file a record of pages visited by a user. The application is made with H-T with loop_context_vars turned on. As a page is visted, its identifying info and a descriptive text is stored in an AoH that is used to build a widget so the user may visit recently seen pages, etc. The problem is thus -- I am storing only the identifying info and a descriptive text. But the AofH in the Session file is showing additional info that looks suspiciously like the loop_context_vars. Here is an excerpt from my Session file -- "rolodex" => [{"ROLODEXVAL" => 3330,"__last__" => 0,"ROLODEXTEXT" => "Puneet Kishor (My Org, Inc.)","__counter__" => undef,"__first__" => 0,"__odd__" => 0,"__inner__" => 0}], See... I only meant to store ROLODEXVAL and ROLODEXTEXT. Where the heck did the __counter__, __first__, etc. come from? Here is the relevant code -- # Create rolodexval my $rolodexval = $res->[0]->{'contact_id'}; # Create rolodextext my $fn= $res->[0]->{'firstname'}; my $ln= $res->[0]->{'lastname'}; my $fullname = ($fn or $ln) ? "$fn $ln" : 'unnamed'; my $org = $res->[0]->{'org'}; my $rolodextext = "$fullname ($org)"; # A hash to hold the current rolodex entry my %rolodexentry = ( ROLODEXVAL => $rolodexval, ROLODEXTEXT => $rolodextext ); # Add the current rolodexentry to the existing rolodex push(@rolodex, \%rolodexentry); # Store the entire AoH in the session $session->param("rolodex", \@rolodex); |