package PL::Template; use strict; use CGI; use HTML::Template; my $q = CGI->new; sub new { my $class = shift; my $self = {}; $self->{template}; $self->{content}; bless $self, $class; return $self; } sub format { my $self = shift; my %params = @_; $self->{content} = $params{content}; my $filter = sub { my $ref = shift; $$ref =~ s/\[aim:\/\/(.*?)\]/$1<\/a>/g; $$ref =~ s/\[google:\/\/(.*?)\]/$1<\/a>/g; $$ref =~ s/\[email:\/\/(.*?)\]/$1<\/a>/g; $$ref =~ s!\[([^|\]]+)\|([^\]]+?)\]!$2!gs; $$ref =~ s|\[([^\]]+?)\]|$1|g; }; my $tmpl= HTML::Template->new( filename => "tmpl/main.tmpl", associate =>$q, loop_context_vars =>1, global_vars=>1, filter => $filter ); $tmpl->param( %{ $self->{content} } ); return $q->header, $tmpl->output(); } sub output { my $self = shift; return $self->format; } 1; ##index.cgi #!perl -w use strict; use PL; my $obj = PL->new; my %content = ( title=>'hi', body=>'hello testing' ); my $page = $obj->Template->format (content => \%content); print $obj->Template->output; ##the template <!--TMPL_VAR name="title"-->
I have attempted numerous methods of formatting my data into an arrayref, only one of which has worked: $tmpl->param( content => [{ title=>'hi'...body=>'testing' }] );