Thread: [htmltmpl] New Template Object based on Existing one
Brought to you by:
samtregar
From: Chris F. <cf...@do...> - 2004-02-08 17:41:03
|
Hey All, I haven't seen a message posted since the 21st, so I wanted to make sure = everything was still working :) Seriously, this may be a silly or even stupid question - but is there = some way to create a new template object and simply assign it all the = params as a existing template object? Something like **** my $content =3D new HTML::Template(filename =3D> "template1.tmpl"); Go through and set all kinds of params my $content2 =3D new HTML::Template(filename =3D> "template2.tmpl"); $content2->param(%$content); $content2 now contains all the params and values that were/are in = $content. **** I know that wouldn't work, just hoping it would help explain. Thanks -Chris |
From: Roger B. W. <ro...@fi...> - 2004-02-08 17:51:47
|
On Sun, Feb 08, 2004 at 12:40:45PM -0500, Chris Faust wrote: >Seriously, this may be a silly or even stupid question - but is there some way to create a new template object and simply assign it all the params as a existing template object? I haven't tried this, but my first reaction is to use the usual syntax for interrogating a template: $content2->param($content->param); Roger |
From: Chris F. <cf...@do...> - 2004-02-08 18:07:32
|
Thanks Roger, I'll give that a try and see what happens. -Chris ----- Original Message ----- From: "Roger Burton West" <ro...@fi...> To: <htm...@li...> Sent: Sunday, February 08, 2004 12:51 PM Subject: Re: [htmltmpl] New Template Object based on Existing one > On Sun, Feb 08, 2004 at 12:40:45PM -0500, Chris Faust wrote: > >Seriously, this may be a silly or even stupid question - but is there some way to create a new template object and simply assign it all the params as a existing template object? > > I haven't tried this, but my first reaction is to use the usual syntax > for interrogating a template: > > $content2->param($content->param); > > Roger > > > ------------------------------------------------------- > The SF.Net email is sponsored by EclipseCon 2004 > Premiere Conference on Open Tools Development and Integration > See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. > http://www.eclipsecon.org/osdn > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: <sa...@es...> - 2004-02-08 18:13:21
|
Roger Burton West wrote: > On Sun, Feb 08, 2004 at 12:40:45PM -0500, Chris Faust wrote: >> Seriously, this may be a silly or even stupid question - but is there=20= >> some way to create a new template object and simply assign it all the=20= >> params as a existing template object? > > I haven't tried this, but my first reaction is to use the usual syntax > for interrogating a template: > > $content2->param($content->param); It's even simpler: simply associate the first object with the second. #!/usr/bin/perl use HTML::Template; my $tmpl =3D new HTML::Template filehandle =3D> \*DATA; $tmpl->param(foo =3D> "bar"); print $tmpl->output; my $str =3D "Second template: foo =3D <TMPL_VAR NAME=3Dfoo>\n"; my $copy =3D new HTML::Template scalarref =3D> \$str, associate =3D> = $tmpl; print $copy->output; __END__ First Template: foo =3D <TMPL_VAR NAME=3Dfoo> =3Dcut will print: $ perl associate.pl First Template: foo =3D bar Second template: foo =3D bar S=E9bastien Aperghis-Tramoni -- - --- -- - -- - --- -- - --- -- - --[ http://maddingue.org ] Close the world, txEn eht nepO= |
From: Chris F. <cf...@do...> - 2004-02-09 15:11:56
|
Roger Burton West wrote: > I haven't tried this, but my first reaction is to use the usual syntax > for interrogating a template: > > $content2->param($content->param); Sébastien Aperghis-Tramoni wrote: > It's even simpler: simply associate the first object with the second. > #!/usr/bin/perl > use HTML::Template; > my $tmpl = new HTML::Template filehandle => \*DATA; > $tmpl->param(foo => "bar"); > print $tmpl->output; > my $str = "Second template: foo = <TMPL_VAR NAME=foo>\n"; > my $copy = new HTML::Template scalarref => \$str, associate => $tmpl; > print $copy->output; Thanks for the suggestions guys, I tried both ways and I got different results with each. That "associate" seemed like the way to go, when I tried that I get the H:T error "attempt to set parameter 'items_loop' with a scalar - parameter is not a TMPL_VAR!" When I tried the "$content2->param($content->param);" method - I'm not really sure what happened, it failed when trying to set a tmpl_var that was the "else" in $content, but $content already contained the flag to mark that value true, plus it seemed to process forever, it took about 2 mins.. I'm going to keep experimenting and see if I can get something to work, if you have any other idea, I'd love to hear them. Thanks -Chris |
From: <hat...@tu...> - 2004-02-09 15:24:26
|
Hello Chris, Monday, February 9, 2004, 5:11:34 PM, you wrote: >> It's even simpler: simply associate the first object with the second. >> #!/usr/bin/perl >> use HTML::Template; >> my $tmpl = new HTML::Template filehandle => \*DATA; >> $tmpl->param(foo => "bar"); >> print $tmpl->output; >> my $str = "Second template: foo = <TMPL_VAR NAME=foo>\n"; >> my $copy = new HTML::Template scalarref => \$str, associate => $tmpl; >> print $copy->output; I think that this can be done more simply: my $copy = new HTML::Template associate => $tmpl; but if I'm not mistaken, when you will call $tmpl->param(foo => 'bar') later, you'll get this param also in $copy -- Best regards, Ãîðüêèé Þðèé mailto:hat...@tu... |
From: Sam T. <sa...@tr...> - 2004-02-09 18:30:47
|
On Mon, 9 Feb 2004, Chris Faust wrote: > That "associate" seemed like the way to go, when I tried that I get the H:T > error > "attempt to set parameter 'items_loop' with a scalar - parameter is not a > TMPL_VAR!" Interesting. I've never tried to associate one template with another one, but I would expect it to work. Can you put together a small test script that generates this error? > When I tried the "$content2->param($content->param);" method That won't work because param() without any args returns a list of parameter names, no values. Try something like this: $content2->param(map { ($_, $content->param($_)) } $content->param()); That takes a list of param names and uses map{} to build a list of (name,value) pairs to pass to param(). -sam |
From: Chris F. <cf...@do...> - 2004-02-09 21:23:01
|
Sam Said, > Interesting. I've never tried to associate one template with another > one, but I would expect it to work. Can you put together a small test > script that generates this error? > Doh!! I appear to be all set Sam.. I couldn't easily take my existing code out as an example as its spread across 2 modules so I spent a few mins creating a test script. When I finished, it worked just fine.. To make a long story short, the loop wasn't being properly defined due to a earlier change, the "associate" had nothing to do with it - I just had a brain lapse between making a change and trying to get something new to work. Sorry about that, but hey... Its working now :).. I'm using Sebastien's suggestion of: my $t2 = new HTML::Template(filename => "email_purchase_results.tmpl", associate => $t1, ); I have a bunch of places where (like a shopping cart) the user is selecting multiple things through multiple form pages, once its done and everything is displayed to the user for conformation/receipt, I have to email it to multiple parties (again like a shopping cart). Using the above I can now have multiple email templates which I can assign all the values of what was just displayed, add some params if needed etc.. and just send it off as a HTML email... No more logic and nothing more then a couple of extra lines of code to do emails!! Maybe nothing special to some, or should have been obvious to me - but I wish I figured this out about a year ago as I would have saved hours upon hours of specialized email creation code, never mind about 5000 db hits a day that I will just go away!! Sam, you're the man.. H::T is awesome!! Thanks -Chris |