CGI::Ex::Template(3)
π CGI::Ex::Template π
okay bestie, so this is the manual page for CGI::Ex::Template from the User Contributed Perl Documentation collection β yes that's the manual name, we're keeping it, it's iconic β and she is literally a Template::Alloy based TT2/TT3/HT/HTE/Tmpl/Velocity engine. six template dialects in one module. main character energy fr fr. π
β¨ VERSION β¨
version 2.55 π
π¦ SYNOPSIS π¦
no cap, here's how you actually use her. she speaks so many languages and you can pick whichever one is your vibe today.
πΈ Template::Toolkit style usage
my $t = Template::Alloy->new(
INCLUDE_PATH => ['/path/to/templates'],
);
my $swap = {
key1 => 'val1',
key2 => 'val2',
code => sub { 42 },
hash => {a => 'b'},
};
# print to STDOUT
$t->process('my/template.tt', $swap)
|| die $t->error;
# process into a variable
my $out = '';
$t->process('my/template.tt', $swap, \$out);
### Alloy uses the same syntax and configuration as Template::Toolkit
like, you pass your INCLUDE_PATH, you build your little $swap hash of values, and then either let her print straight to STDOUT or catch the output in a variable by passing a scalar ref. and yes β she uses the exact same syntax and configuration as Template::Toolkit, so if you already know TT, you already know her. periodt. π
π§ HTML::Template::Expr style usage
my $t = Template::Alloy->new(
filename => 'my/template.ht',
path => ['/path/to/templates'],
);
my $swap = {
key1 => 'val1',
key2 => 'val2',
code => sub { 42 },
hash => {a => 'b'},
};
$t->param($swap);
# print to STDOUT (errors die)
$t->output(print_to => \*STDOUT);
# process into a variable
my $out = $t->output;
### Alloy can also use the same syntax and configuration as HTML::Template
different vibe, same queen. here you give her a filename and a path, shove your values in with param, and then call output. heads up: when you call output and print to STDOUT, errors die β so like, she will not be quiet about it bestie. π and yeah, she can run the same syntax and configuration as HTML::Template too.
π Text::Tmpl style usage
my $t = Template::Alloy->new;
my $swap = {
key1 => 'val1',
key2 => 'val2',
code => sub { 42 },
hash => {a => 'b'},
};
$t->set_delimiters('#[', ']#');
$t->set_strip(0);
$t->set_values($swap);
$t->set_dir('/path/to/templates');
my $out = $t->parse_file('my/template.tmpl');
my $str = "Foo #[echo $key1]# Bar";
my $out = $t->parse_string($str);
### Alloy uses the same syntax and configuration as Text::Tmpl
now we're in Text::Tmpl territory β you set your own delimiters with set_delimiters('#[', ']#'), you set strip with set_strip(0), you drop your values in with set_values, and you tell her where to look with set_dir('/path/to/templates'). then it's parse_file for files or parse_string for a raw string. obsessed. and yep, same syntax and configuration as Text::Tmpl. π₯
β Velocity (VTL) style usage
my $t = Template::Alloy->new;
my $swap = {
key1 => 'val1',
key2 => 'val2',
code => sub { 42 },
hash => {a => 'b'},
};
my $out = $t->merge('my/template.vtl', $swap);
my $str = "#set($foo 1 + 3) ($foo) ($bar) ($!baz)";
my $out = $t->merge(\$str, $swap);
and finally, Velocity VTL mode β you just merge a file path, or merge a reference to a string if you wanna go inline. look at that #set($foo 1 + 3) doing math in a template like she's unbothered. iconic. π
π DESCRIPTION π
okay so, lore time. CGI::Ex::Template is the original base for the code that is now Template::Alloy. Template::Alloy picked up enough complexity and featureset that it warranted moving out into its own separate namespace. she outgrew the apartment, basically. π¦
so now? CGI::Ex::Template is a place holder subclass of Template::Alloy. you can use CGI::Ex::Template as a standalone module β nobody's stopping you β but the suggestion on the table is that you use Template::Alloy directly instead. ngl, listen to the suggestion. π
for examples of usage, configuration, syntax, bugs, vmethods, directives, etc. β like, all of it β please refer to the Template::Alloy documentation. that's where the whole story lives bestie. β¨
π LICENSE π
this module may be distributed under the same terms as Perl itself. slay, free and open, as she should be. π
π«Ά AUTHOR π«Ά
Paul Seamons <perl at seamons dot com> β thank you for your service, king. π
and that's the whole page bestie!! this was rendered by perl v5.42.0 on 2025-07-25, and the page itself is CGI::Ex::Template(3). go forth and template responsibly. πβ¨ππ¦πΈ
π¦ where this page comes from
- fedora 43: perl-CGI-Ex 2.55-6.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms