Dancer2...gReport(3)

πŸ“¦
version 2.03 Β· 2 versions
, in fedora 44

πŸ’– Dancer2::Template::TTLogReport(3) πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation β€” the manual for Dancer2::Template::TTLogReport, no cap ✨


🌸 NAME 🌸

Dancer2::Template::TTLogReport β€” it's a Template Toolkit engine for Dancer2 that comes with Log::Report translations baked in πŸŽ€


πŸ¦‹ INHERITANCE πŸ¦‹

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

so like, it's a Moo::Object at heart πŸ’œ


✨ SYNOPSIS ✨

Wanna use this engine? literally just set it up in your config.yaml:

template:   "TTLogReport"

Orrr you can swap the rendering engine on a per-route basis by setting it manually with set, which is giving very much main-character flexibility πŸ’…

set template => 'TTLogReport';

And here's the whole app vibe:

# 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 lets you use Template::Toolkit inside Dancer2, and it also brings along the translation extensions that Log::Report::Template offers. it's giving bilingual icon behaviour 🌈


πŸ’… METHODS πŸ’…

🧚 Constructors

Standard Moo, with Dancer2::Core::Role::Template extensions. that's it, that's the whole vibe 🫢

πŸ“ Attributes

  • $obj->tt() β€” hands you back the Log::Report::Template object that's doing the actual template processing. this object gets instantiated based on the values it finds in the Dancer2 configuration file πŸ’–

πŸ”₯ Action

  • $obj->addTextDomain(%options) β€” forwards the %options straight through to Log::Report::Template::addTextdomain(). no gatekeeping, it just passes them along ✨

Β» 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, obviously πŸ’… The first arg is either a filename for the template file, or a reference to a string that contains the template. The second arg is a hashref of the tokens you wanna pass to Template::Toolkit for rendering.

And when a translation language is set, this renderer goes ahead and adds these variables for you: language (like nl), language_territory (like nl_BE), and locale (like nl_BE.utf8). freebies, slay 🌸


🌈 DETAILS 🌈

πŸŽ€ Dancer2 Configuration

Most of the configuration variables that are available when you create 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. So if you're tryna use PHP-style tags, you'll need to list them as <\? and \?>.) Peep Template::Manual::Config for the configuration variables πŸ“š

On top of the standard configuration variables, there's also the option show_private_variables. Template::Toolkit, by default, does not render private variables β€” those are the ones starting with an underscore. So if in your project it's easier to disable this feature than to go renaming all your variables, just 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! so like, be careful bestie 😭

🧡 Advanced Customization

The module Dancer2::Template::TemplateToolkit describes how to extend the Template by wrapping the _build_engine method. But the instantiation trick is insufficient for slightly more complex modules β€” like our Log::Report translation feature, for instance. 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 Dancer2-Plugin-LogReport version 2.03, built on April 13, 2026. Website: http://perl.overmeer.net/CPAN/ β€” go look, iykyk πŸ¦‹


🫢 LICENSE 🫢

For contributors see file ChangeLog.

This software is copyright (c) 2015-2026 by Mark Overmeer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt πŸ’…


and that's a wrap, bestie πŸ’– this was perl v5.42.1, dated 2026-04-13 β€” take care of yourself and go read your config files 🌸✨

πŸ“¦ where this page comes from