NAME

Dancer2::Template::TTLogReport - Template toolkit engine with Log::Report translations for Dancer2

INHERITANCE

Dancer2::Template::TTLogReport
  is a Moo::Object

SYNOPSIS

To use this engine, you may configure Dancer2 via config.yaml:

template:   "TTLogReport"

Or you may also change the rendering engine on a per-route basis by setting it manually with set:

set template => 'TTLogReport';

Application:

# In your daemon startup
my $pot    = Log::Report::Translator::POT->new(lexicon => $poddir);
my $domain = (engine 'template')->addTextdomain(name => $mydomain);
$domain->configure(translator => $pot);

# Use it:
get '/' => sub {
  template index => {
      title        => 'my webpage',

      # The actual language is stored in the user session.
      translate_to => 'nl_NL.utf-8',
  };
};

DESCRIPTION

This template engine allows you to use Template::Toolkit in Dancer2, including the translation extensions offered by Log::Report::Template.

METHODS

Constructors

Standard Moo with Dancer2::Core::Role::Template extensions.

Accessors

$obj->tt()

Returns the Log::Report::Template object which is performing the template processing. This object gets instantiated based on values found in the Dancer2 configuration file.

Action

$obj->addTextDomain(%options)

Forwards the %options to Log::Report::Template::addTextdomain().

example:

my $lexicon = $directory;  # f.i. $directory/<domain>/nl_NL.utf-8.po
my $tables  = Log::Report::Translator::POT->new(lexicon => $lexicon);
(engine 'template')->addTextdomain(name => 'mydomain')->configure(translator => $tables);
$obj->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 Template::Toolkit for rendering.

When a translation language is set, then this renderer adds the following variables: language (like "nl"), language_territory (like "nl_BE"), and locale (like "nl_BE.utf8").

DETAILS

Dancer2 Configuration

Most configuration variables are available when creating a new instance of a Template::Toolkit object can be declared in your config.yml file. For example:

template: TTLogReport

engines:
  template:
    TTLogReport:
      start_tag: '<%'
      end_tag:   '%>'

(Note: start_tag and end_tag are regexes. If you want to use PHP-style tags, you will need to list them as <\? and \?>.) See Template::Manual::Config for the configuration variables.

In addition to the standard configuration variables, the option show_private_variables is also available. Template::Toolkit, by default, does not render private variables (the ones starting with an underscore). If in your project it gets easier to disable this feature than changing variable names, add this option to your configuration.

show_private_variables: true

Warning: Given the way Template::Toolkit implements this option, different Dancer2 applications running within the same interpreter will share this option!

Advanced Customization

Module Dancer2::Template::TemplateToolkit describes how to extend the Template by wrapping the _build_engine method. The instantiation trick is insufficient for a bit more complex modules, like our Log::Report translation feature. You may be able to extend this module with your own templater, however.

# in config.yml
engines:
  template:
    TTLogReport:
      start_tag: '<%'
      end_tag:   '%>'
      templater: Log::Report::Template  # default

SEE ALSO

This module is part of Log-Report-Template distribution version 1.02, built on July 29, 2025. Website: http://perl.overmeer.net/CPAN/

LICENSE

Copyrights 2017-2025 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/