Template::Tiny(3)
π Template::Tiny π
okay bestie, so this is Template::Tiny β Template Toolkit reimplemented in as little code as possible. literally the β¨tinyβ¨ version. it's giving minimal but make it fashion π
β¨ VERSION β¨
version 1.16 β yeah she's on 1.16, slay π
πΈ SYNOPSIS πΈ
my $template = Template::Tiny->new(
TRIM => 1,
);
# Print the template results to STDOUT
$template->process( <<'END_TEMPLATE', { foo => 'World' } );
Hello [% foo %]!
END_TEMPLATE
see? that's it. that's the whole vibe. π¦
π DESCRIPTION π
so like, Template::Tiny is a reimplementation of a subset of the functionality from Template Toolkit, crammed into as few lines of code as possible. she's a small queen. π
she's made for the situations where you're doing light-usage, low-memory, or low-cpu templating β like, maybe you'll need to upgrade to the full feature set later, or maybe you just want to keep that familiar TT-style template feel, iykyk. π«Ά
for the subset of functionality she actually implements, she has a fully-compatible template and stash API. meaning: all templates used with Template::Tiny should be able to be transparently upgraded to full Template Toolkit. no drama, no rewrite, just glow-up energy β¨
and here's the iconic part β unlike Template Toolkit, Template::Tiny will process templates without a compile phase. but despite this she is still quicker, owing to heavy use of the Perl regular expression engine. not me being fast AND lazy π
π§ SUPPORTED USAGE π§
unless otherwise specified, the default Template Toolkit [% %] tag style is used. if you want different opening and closing tags, specify these when creating your Template::Tiny object:
my $template = Template::Tiny->new( start_tag => '<%', end_tag => '%>' );
(for the remainder of the documentation, [% %] tags are assumed, bestie)
both the [%+ +%] style explicit whitespace and the [%- -%] style explicit chomp are supported β although the [%+ +%] version is unneeded in practice, since Template::Tiny does not support default-enabled PRE_CHOMP or POST_CHOMP. so like, you can, but you don't gotta πΈ
variable expressions in the form [% foo.bar.baz %] are supported. periodt. π
appropriate simple behaviours for ARRAY references, HASH references and objects are supported. VMethods such as [% array.length %] are not supported at this time. sorry bestie, not yet π
IF, ELSE and UNLESS conditional blocks are supported β but only with simple [% foo.bar.baz %] conditions. keep it simple, she's tiny π
support for looping (or rather, iteration) is available in simple [% FOREACH item IN list %] form. other loop structures are not supported. and because support for arbitrary or infinite looping is not available, Template::Tiny templates are not turing complete. this is intentional. π
all of the four supported control structures β IF / ELSE / UNLESS / FOREACH β can be nested to arbitrary depth. go off, structure queen π₯
the treatment of _private hash and method keys is compatible with Template Toolkit: returning null or false rather than the actual content of the hash key or method. private stays private, as she should π
anything beyond the above is currently out of scope. that's the boundary, bestie π
β METHODS β
π¦ new π¦
my $template = Template::Tiny->new(
TRIM => 1,
start_tag => '<%',
end_tag => '%>',
);
the new constructor is provided for compatibility with Template Toolkit. it's the same handshake, different girl π«Ά
the only parameters currently supported are:
TRIMβ removes leading and trailing whitespace from processed templatesstart_tagβ changes the starting tag identifier from[%end_tagβ changes the ending tag identifier from%]
additional parameters can be provided without error, but will be ignored. she's polite, she just won't use them π
π process π
# DEPRECATED: Return template results (emits a warning)
my $text = $template->process( \$input, $vars );
# Print template results to STDOUT
$template->process( \$input, $vars );
# Generate template results into a variable
my $output = '';
$template->process( \$input, $vars, \$output );
the process method is called to process a template. main character method energy honestly π
the first parameter is a reference to a text string containing the template text. a reference to a hash may be passed as the second parameter, containing definitions of template variables. πΈ
if a third parameter is provided, it must be a scalar reference to be populated with the output of the template. β¨
for a limited amount of time, the old deprecated interface will continue to be supported. if process is called without a third parameter, and in scalar or list context, the template results will be returned to the caller. β οΈ
if process is called without a third parameter, and in void context, the template results will be print()ed to the currently selected file handle (probably STDOUT) for compatibility with Template. π
π₯ SEE ALSO π₯
Template::Tiny::Strict, Config::Tiny, CSS::Tiny, YAML::Tiny β the whole tiny cinematic universe, we love a crossover π«Ά
π SUPPORT π
bugs may be submitted through the RT bug tracker at https://rt.cpan.org/Public/Dist/Display.html?Name=Template-Tiny (or bug-Template-Tiny@rt.cpan.org / mailto:bug-Template-Tiny@rt.cpan.org).
like, please actually report them, she wants to grow π±
π AUTHOR π
Adam Kennedy <adamk@cpan.org>
π CONTRIBUTORS π
- Adam Kennedy
<adam@ali.as> - Karen Etheridge
<ether@cpan.org> - Jason A. Crome
<jason@crome-plated.com> - Alexandr Ciornii
<alexchorny@gmail.com> - Matt S Trout
<mst@shadowcat.co.uk>
the group chat that made her iconic, no cap π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2009 by Adam Kennedy.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in bestie, go wild π
okay and one last thing β this whole page is from the User Contributed Perl Documentation collection, and it's documenting perl v5.42.0, dated 2025-07-25. so when you cite her, cite her properly bestie π β¨ bye ily, go template something tiny π¦π
π¦ where this page comes from
- fedora 43: perl-Template-Tiny 1.16-2.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