Thread: [htmltmpl] Getting data from template?
Brought to you by:
samtregar
From: Lyle <web...@co...> - 2009-01-29 04:10:01
|
Hi All, I'm trying to find a way to get data into my script from my template. I've tried:- <tmpl_var name=test default="HELLO!"> And then after loading the template in my code:- print $template->param( 'test' ); But that doesn't work. Is there a way to pickup data from a template you've read in? Lyle |
From: Roger B. W. <ro...@fi...> - 2009-01-29 09:49:25
|
On Thu, Jan 29, 2009 at 03:21:59AM +0000, Lyle wrote: >But that doesn't work. Is there a way to pickup data from a template >you've read in? This is quite a common question, and the answer is "yes". My own HTML::Template::Set extension is one approach. See the list archives. Roger |
From: Lyle <web...@co...> - 2009-01-29 12:15:34
|
Roger Burton West wrote: > On Thu, Jan 29, 2009 at 03:21:59AM +0000, Lyle wrote: > > >> But that doesn't work. Is there a way to pickup data from a template >> you've read in? >> > > This is quite a common question, and the answer is "yes". My own > HTML::Template::Set extension is one approach. See the list archives. > Hi Roger, Excellent! Just what I was looking for. My bad I should have thought to look in the HTML::Template namespace. Lyle |
From: Lyle <web...@co...> - 2009-01-29 21:15:25
|
Roger Burton West wrote: > On Thu, Jan 29, 2009 at 03:21:59AM +0000, Lyle wrote: > > >> But that doesn't work. Is there a way to pickup data from a template >> you've read in? >> > > This is quite a common question, and the answer is "yes". My own > HTML::Template::Set extension is one approach. See the list archives. > Is there a version that works with HTML::Template::Pro? I'm using a template system that loads HTML::Template::Pro if available (for the speed enhancements) otherwise defaults to the normal HTML::Template. I'd need to be able to use HTML::Template::Set with both of them. Lyle |
From: Michael P. <mp...@pl...> - 2009-01-29 21:26:38
|
Lyle wrote: > Is there a version that works with HTML::Template::Pro? I'm using a > template system that loads HTML::Template::Pro if available (for the > speed enhancements) Really? Did you do benchmarks and find that your templating was bottleneck? And if so, how much of a gain did you get from HTML::Template::Pro? If page takes 1 sec to create on the server and your templating takes only 10% of your execution time (and I've never had a real page where that was the case, it's usually closer to 2-5%) and you increase the speed of your templating by 25x (that's the max claimed by H::T::P) then you've taken a full 0.096 sec off. That little gain is just not worth it to me if you have to jump through hoops to make other things with with the module (like you're trying to do with H::T::Sec). Plus it doesn't support query() which I find extremely handy. -- Michael Peters Plus Three, LP |
From: Mathew R. <mat...@ne...> - 2009-01-29 23:42:38
|
>> Is there a version that works with HTML::Template::Pro? I'm using a >> template system that loads HTML::Template::Pro if available (for the >> speed enhancements) >> > > Really? Did you do benchmarks and find that your templating was bottleneck? And if so, how much of a > gain did you get from HTML::Template::Pro? If page takes 1 sec to create on the server and your > templating takes only 10% of your execution time (and I've never had a real page where that was the > case, it's usually closer to 2-5%) and you increase the speed of your templating by 25x (that's the > max claimed by H::T::P) then you've taken a full 0.096 sec off. > > That little gain is just not worth it to me if you have to jump through hoops to make other things > with with the module (like you're trying to do with H::T::Sec). Plus it doesn't support query() > which I find extremely handy. > I did some performance profiling of H::T some time ago -> it turns out that there is quite a bit of speed up (somewhere between 10% and 10x, depending on the page) by re-writing part of the code located around line 2660. hope this helps, Mathew patch -> replace the options{associate} conditional with this: # support the associate magic, searching for undefined params and # attempting to fill them from the associated objects. if (scalar(@{$options->{associate}})) { my @undef_params; foreach my $param (keys %{$self->{param_map}}) { next if (defined $self->param($param)); push @undef_params, $param; } if (scalar(@undef_params)) { my $value; # if case sensitive mode or no CGI objects, we can use the fast path if ($options->{case_sensitive} or (grep { !/^1/ } map { UNIVERSAL::isa($_,'HTML::Template') } @{$options->{associate}}) == 0) { foreach my $param (@undef_params) { foreach my $associated_object (reverse @{$options->{associate}}) { $value = $associated_object->param($param); next unless (defined $value); $self->param($param, scalar $value); last; } } } else { my %case_map; foreach my $associated_object (@{$options->{associate}}) { map { $case_map{$associated_object}{lc($_)} = $_ } $associated_object->param(); } my $associated_param; foreach my $param (@undef_params) { foreach my $associated_object (reverse @{$options->{associate}}) { $associated_param = $case_map{$associated_object}{$param}; next unless (defined $associated_param); $value = $associated_object->param($associated_param); next unless (defined $value); $self->param($param, scalar $value); last; } } } } } |
From: Lyle <web...@co...> - 2009-01-30 00:02:10
|
Mathew Robertson wrote: > >>> Is there a version that works with HTML::Template::Pro? I'm using a >>> template system that loads HTML::Template::Pro if available (for the >>> speed enhancements) >>> >> >> Really? Did you do benchmarks and find that your templating was bottleneck? And if so, how much of a >> gain did you get from HTML::Template::Pro? If page takes 1 sec to create on the server and your >> templating takes only 10% of your execution time (and I've never had a real page where that was the >> case, it's usually closer to 2-5%) and you increase the speed of your templating by 25x (that's the >> max claimed by H::T::P) then you've taken a full 0.096 sec off. > I did some performance profiling of H::T some time ago -> it turns out > that there is quite a bit of speed up (somewhere between 10% and 10x, > depending on the page) by re-writing part of the code located around > line 2660. Does this pass all the .t tests? If it does then shouldn't this get accepted into H::T as a patch? Care to supply the change as a diff? Sorry for the shameless blog plug, but I only learnt how to use diff and patch recently and blogged about how to to do:- http://perl.bristolbath.org/blog/lyle/2009/01/how-to-submit-perl-patches.html#more Lyle |
From: Mathew R. <mat...@ne...> - 2009-01-30 03:46:28
|
>> I did some performance profiling of H::T some time ago -> it turns out >> that there is quite a bit of speed up (somewhere between 10% and 10x, >> depending on the page) by re-writing part of the code located around >> line 2660. >> > > Does this pass all the .t tests? If it does then shouldn't this get > accepted into H::T as a patch? Care to supply the change as a diff? > > Sorry for the shameless blog plug, but I only learnt how to use diff and > patch recently and blogged about how to to do:- > http://perl.bristolbath.org/blog/lyle/2009/01/how-to-submit-perl-patches.html#more > Not sure if it passes every test -> I use a heavily modified version of H::T which supports dynamic loading of escape-modules, support for arbitrary TMPL_xxx syntax, an odd bug fix + some other goodies... so I haven't specifically tested it against 2.10. That same reason also makes it hard to generate an isolated patch. I have posted this code before, but AFAICR there wasn't much discussion of merging it. cheers, Mathew |