package Dancer2::Template::Tiny; # ABSTRACT: Template::Tiny engine for Dancer2 $Dancer2::Template::Tiny::VERSION = '2.1.0'; use Moo; use Carp qw/croak/; use Path::Tiny (); use Dancer2::Core::Types; use Template::Tiny; with 'Dancer2::Core::Role::Template'; has '+engine' => ( isa => InstanceOf ['Template::Tiny'] ); sub _build_engine { Template::Tiny->new( %{ $_[0]->config } ); } sub render { my ( $self, $template, $tokens ) = @_; ( ref $template || -f $template ) or croak "$template is not a regular file or reference"; my $template_data = ref $template ? ${$template} : Path::Tiny::path($template)->slurp_utf8; # Template::Tiny doesn't like empty template files (like .dancer), so # don't try to render them. Return an empty (not undef) value instead. return '' unless $template_data; my $content; $self->engine->process( \$template_data, $tokens, \$content, ) or die "Could not process template file '$template'"; return $content; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Dancer2::Template::Tiny - Template::Tiny engine for Dancer2 =head1 VERSION version 2.1.0 =head1 SYNOPSIS This template engine allows you to use L in L. L is an implementation of a subset of L (the major parts) but takes much less memory and is faster. If you're only using the main functions of Template::Toolkit, you could use Template::Tiny. You can also seamlessly move back to Template::Toolkit whenever you want. To use this engine, all you need to configure in your L's C: template: "tiny" Of course, you can also set this B working using C: # code code code set template => 'tiny'; Since L has internal support for a wrapper-like option with the C configuration option, you can have a L-like WRAPPER even though L doesn't really support it. =head1 METHODS =head2 render($template, \%tokens) Renders the template. The first arg is a filename for the template file or a reference to a string that contains the template. The second arg is a hashref for the tokens that you wish to pass to L for rendering. =head1 SEE ALSO L, L, L. =head1 AUTHOR Dancer Core Developers =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2026 by Alexis Sukrieh. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut