Template::Alloy also provides ways to do what you want. In addition to supporting all of HTML::Template and HTML::Template::Expr, it also allows for using TT tags in your templates as well - and as a plus Template::Alloy is faster than HTML::Template.
The following code shows inserting dynamic page content in two ways: passing a variable to the PROCESS directive, and the second way is passing raw text to eval (eval simply uses the current template object and parses the text that is passed as a template - if normal cache options are set, this method can still be very fast).
use Template::Alloy;
use POSIX qw(tmpnam);
my $file1 = tmpnam;
my $file2 = tmpnam;
END { unlink $file1 };
END { unlink $file2 };
if (open my $fh, ">", $file1) {
print $fh "I am file1 ($file1).
title = (<TMPL_VAR name=title>).
page = (<TMPL_VAR name=page>).
------------------
<TMPL_PROCESS \$page>
------------------
<TMPL_GET page3.eval>
";
close $fh;
}
if (open my $fh2, ">", $file2) {
print $fh2 "I am file2 ($file1).
title = (<TMPL_VAR name=title>).
";
close $fh2;
}
my $ht = Template::Alloy->new(filename => $file1, absolute => 1);
$ht->param(title => 'The title');
$ht->param(page => $file2);
$ht->param(page3 => sub { "This is a dynamically included string.\ntit
+le = (<TMPL_VAR name=title>)\n"});
print $ht->output;
__END__
prints
I am file1 (/tmp/filessyE4j).
title = (The title).
page = (/tmp/filez6O6TO).
------------------
I am file2 (/tmp/filessyE4j).
title = (The title).
------------------
This is a dynamically included string.
title = (The title)
my @a=qw(random brilliant braindead); print $a[rand(@a)];