Mojoli...oolkit(3pm)

πŸ’– Mojolicious::Plugin::TemplateToolkit β€” the perl v5.36.0 era, dated 2023-02-24, and living in the User Contributed Perl Documentation corner of section 3pm πŸ’–

okay bestie, sit down, hydrate, because this is the page for Mojolicious::Plugin::TemplateToolkit and it's genuinely so useful. it's a Template Toolkit renderer plugin for Mojolicious, which is exactly what it sounds like and also exactly what the NAME section says. no cap.


✨ NAME ✨

Mojolicious::Plugin::TemplateToolkit β€” Template Toolkit renderer plugin for Mojolicious. that's it, that's the whole name, she's concise and she knows it πŸ’…


🌸 SYNOPSIS 🌸

here's the whole vibe, copy-paste ready, verbatim, do not touch:

# Mojolicious
$app->plugin('TemplateToolkit');
$app->plugin(TemplateToolkit => {name => 'foo'});
$app->plugin(TemplateToolkit => {template => {INTERPOLATE => 1}});

# Mojolicious::Lite
plugin 'TemplateToolkit';
plugin TemplateToolkit => {name => 'foo'};
plugin TemplateToolkit => {template => {INTERPOLATE => 1}});

# Set as default handler
$app->renderer->default_handler('tt2');

# Render without setting as default handler
$c->render(template => 'bar', handler => 'tt2');
heads up babes: that third Lite line has a lil extra ) hanging out at the end in the original. i am not fixing it, i am reporting it. character for character, periodt.

πŸ¦‹ DESCRIPTION πŸ¦‹

so Mojolicious::Plugin::TemplateToolkit is a renderer for tt2 or Template Toolkit templates. if you wanna know the deets on the Template Toolkit format itself, go read Template and Template::Manual. if you wanna know the general tea about rendering in Mojolicious, go read Mojolicious::Guides::Rendering. iykyk.

here's the part that actually matters: along with template files, inline and data section templates can be rendered in the standard Mojolicious fashion. and here's the plot twist β€” template files and data sections get retrieved using Mojolicious::Renderer via Template::Provider::Mojo, and that's true for both direct rendering and directives like INCLUDE. which means: instead of specifying INCLUDE_PATH, you should set paths in Mojolicious::Renderer to the appropriate paths. yes, that's a whole redirect of your brain, i know.

$app->renderer->paths(['/path/to/templates']);
push @{$app->renderer->paths}, '/path/to/more/templates';

Mojolicious stash values get exposed directly as variables in the templates, and the current controller object is available as c or self β€” same energy as Mojolicious::Plugin::EPRenderer, bestie, it's giving consistency. πŸ‘‘

helper methods can be called on the controller object as normal, and on a proxy object available as h. now, the lore: that proxy object was previously needed for efficiency, because the controller object used AUTOLOAD to call helper methods. but since Mojolicious 8.04 the controller object uses a more efficient mechanism, so the proxy object is no longer needed. character development!! if you want the full list of all built-in helper methods, go look at Mojolicious::Plugin::DefaultHelpers and Mojolicious::Plugin::TagHelpers.

big serious note: accessing helper methods directly as variables, rather than via the controller or proxy object, is deprecated and may be removed in a future release. don't build your whole personality on it. 😭

and here's the example, exactly as written:

$c->stash(description => 'template engine');
$c->stash(engines => [qw(Template::Toolkit Text::Template)]);

[% FOREACH engine IN engines %]
  [% engine %] is a [% description %].
[% END %]

[% c.link_to('Template Toolkit', 'http://www.template-toolkit.org') %]

[% c.param('foo') %]

πŸŽ€ OPTIONS πŸŽ€

Mojolicious::Plugin::TemplateToolkit supports the following options. only two, but they're both doing their thing.

⭐ name

# Mojolicious::Lite
plugin TemplateToolkit => {name => 'foo'};

handler name, and it defaults to tt2. that's the whole thing. short and sweet.

⭐ template

# Mojolicious::Lite
plugin TemplateToolkit => {template => {INTERPOLATE => 1}};

configuration values passed to the Template object used to render templates. and ⚠️ listen closely: Template::Provider::Mojo will use paths in Mojolicious::Renderer to find templates β€” not INCLUDE_PATH specified here. do not come for me when you put INCLUDE_PATH in this option and it does nothing, because i warned you. πŸ™ˆ


πŸ’… METHODS πŸ’…

Mojolicious::Plugin::TemplateToolkit inherits all methods from Mojolicious::Plugin and implements the following new ones. one (1) new one. she's focused.

🌈 register

$plugin->register(Mojolicious->new);
$plugin->register(Mojolicious->new, {name => 'foo'});

register renderer in Mojolicious application. that's the job. she does it. ✨


πŸ’€ BUGS πŸ’€

report any issues on the public bugtracker. that's it, that's the section, go be a good citizen.


πŸ‘‘ AUTHOR πŸ‘‘

Dan Book <dbook@cpan.org> β€” legend behaviour, honestly.


This software is Copyright (c) 2015 by Dan Book.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

free software, bestie!! the good stuff!! 🫢


🌟 SEE ALSO 🌟

  • Mojolicious::Renderer
  • Template
  • Template::Provider::Mojo

and that's the whole page, no crumbs left behind 🧚✨

one last thing before you close this tab β€” this whole thing lives in perl v5.36.0, last touched 2023-02-24, filed under User Contributed Perl Documentation as Mojoli...oolkit(3pm). yes the title got truncated, she's mysterious like that. bye bestie, go render something cute πŸ’–πŸŒΈ