Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grinnz/mojolicious-plugin-templatetoolkit

Mojolicious::Plugin::TemplateToolkit - Template Toolkit renderer plugin for Mojolicious
https://github.com/grinnz/mojolicious-plugin-templatetoolkit

Last synced: 5 days ago
JSON representation

Mojolicious::Plugin::TemplateToolkit - Template Toolkit renderer plugin for Mojolicious

Awesome Lists containing this project

README

        

=pod

=head1 NAME

Mojolicious::Plugin::TemplateToolkit - Template Toolkit renderer plugin for
Mojolicious

=head1 SYNOPSIS

# 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');

=head1 DESCRIPTION

L is a renderer for C or
C templates. See L and L for
details on the C format, and L
for general information on rendering in L.

Along with template files, inline and data section templates can be rendered in
the standard Mojolicious fashion. Template files and data sections will be
retrieved using L via L for
both direct rendering and directives such as C. This means that
instead of specifying L,
you should set L to the appropriate paths.

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

L stash values will be exposed directly as
L in the templates, and the current
controller object will be available as C or C, similar to
L.

Helper methods can be called on the controller object as normal, as well as on
a L available as C. The
proxy object was previously needed for efficiency as the controller object used
C to call helper methods, but since Mojolicious 8.04 the controller
object uses a more efficient mechanism and the proxy object is no longer
needed. See L and
L for a list of all built-in helper methods.

Accessing helper methods directly as variables, rather than via the controller
or proxy object, is deprecated and may be removed in a future release.

$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') %]

=head1 OPTIONS

L supports the following options.

=head2 name

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

Handler name, defaults to C.

=head2 template

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

Configuration values passed to L object used to render templates.
Note that L will use L
to find templates, not L
specified here.

=head1 METHODS

L inherits all methods from
L and implements the following new ones.

=head2 register

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

Register renderer in L application.

=head1 BUGS

Report any issues on the public bugtracker.

=head1 AUTHOR

Dan Book

=head1 COPYRIGHT AND LICENSE

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

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

=head1 SEE ALSO

L, L, L

=cut