I may be missing something terribly obvious, but the version of HTML::Template::Set that you pasted doesn't really work:
#!/usr/bin/perl use strict; my $tmpl = '<!-- tmpl_set name="foo" value="bar" --><h1><!-- tmpl_var foo--></h1>'; my $template = HTML::Template::Set->new( scalarref => \$tmpl, ); print $template->output; Gives you an error: HTML::Template->new() : fatal error occured during filter call: "foo" at test.pl line 6 at test.pl line 6 The version of HTML::Template::Set that's on CPAN right now is from 2004 and is a lot, and I mean a LOT different (and complex). I liked your version better, but it doesn't seem to be doing the right thing, sadly. Justin On Jul 23, 2009, at 9:40 AM, Roger Burton West wrote: > On Thu, Jul 23, 2009 at 03:56:36PM +0100, Stuart Moore wrote: >> Is there any way to set a variable within a template? > > No. I tend to use my HTML::Template::Set extension, which is very > basic > but gets the job done. I think this is the latest version. It allows > you to: > > <tmpl_set name=varname value=varvalue> > > Roger > > > > > 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; > > > ------------------------------------------------------------------------------ > _______________________________________________ > Html-template-users mailing list > Html-template-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/html-template-users > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Html-template-users mailing list Html-template-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/html-template-users