Re: [htmltmpl] Re: H::T future
Brought to you by:
samtregar
From: Roger B. W. <ro...@fi...> - 2003-12-10 09:46:15
|
On Wed, Dec 10, 2003 at 12:18:52PM +1100, Mathew Robertson wrote: >Is this implemented as a filter? In any case, I would be interested in having a look at how you did this. Very much like the param version just posted here. Insert tags of the form: <tmpl_set name=x value=y> with _no_ quoting around the x and y (this is a quick-and-dirty hack); each one will provide a value for a top-level parameter. You can't do anything about values within loops with this. package HTML::Template::Set; use HTML::Template; use base qw(HTML::Template); sub new { my %set_params; my $set_filter = sub { my $text_ref=shift; my $match='<(?:\!--\s*)?tmpl_set\s*name=(.*?)\s*value=(.*?)\s*(?:--)?>'; my @taglist=$$text_ref =~ m/$match/gi; while (@taglist) { my ($t,$v)=(shift @taglist,shift @taglist); $set_params{$t}=$v; } $$text_ref =~ s/$match/<tmpl_if name=never><tmpl_var name=$1><\/tmpl_if>/gi; }; my $proto = shift; my $class = ref($proto) || $proto; my $self=HTML::Template->new(filter => $set_filter, @_); bless ($self, $class); $self->param(%set_params); return $self; } 1; |