1Dancer::Template::TemplUasteerToCoolnktirti(b3u)ted PerlDaDnocceurm:e:nTteamtpiloante::TemplateToolkit(3)
2
3
4

NAME

6       Dancer::Template::TemplateToolkit - Template Toolkit wrapper for Dancer
7

VERSION

9       version 1.3513
10

DESCRIPTION

12       This class is an interface between Dancer's template engine abstraction
13       layer and the Template module.
14
15       This template engine is recommended for production purposes, but
16       depends on the Template module.
17
18       In order to use this engine, use the template setting:
19
20           template: template_toolkit
21
22       This can be done in your config.yml file or directly in your app code
23       with the set keyword.
24
25       Note that by default,  Dancer configures the Template::Toolkit engine
26       to use <% %> brackets instead of its default [% %] brackets.  This can
27       be changed within your config file - for example:
28
29           template: template_toolkit
30           engines:
31               template_toolkit:
32                   start_tag: '[%'
33                   stop_tag: '%]'
34
35       You can also add any options you would normally add to the Template
36       module's initialization. You could, for instance, enable saving the
37       compiled templates:
38
39           engines:
40               template_toolkit:
41                   COMPILE_DIR: 'caches/templates'
42                   COMPILE_EXT: '.ttc'
43
44       Note though that unless you change them, Dancer sets both of the
45       Template options "ANYCASE" and "ABSOLUTE" on, as well as pointing
46       "INCLUDE_PATH" to your views directory and setting "ENCODING" to your
47       charset setting.
48

SUBCLASSING

50       By default, Template is used, but you can configure Dancer to use a
51       subclass of Template with the "subclass" option.
52
53           engines:
54               template_toolkit:
55                   subclass: My::Template
56
57       When used like this, Dancer skips the defaults mentioned above.  Only
58       those included in your config file are sent to the subclass.
59

WRAPPER, META variables, SETs

61       Dancer already provides a WRAPPER-like ability, which we call a
62       "layout". The reason we do not use TT's WRAPPER (which also makes it
63       incompatible with it) is because not all template systems support it.
64       Actually, most don't.
65
66       However, you might want to use it, and be able to define META variables
67       and regular Template::Toolkit variables.
68
69       These few steps will get you there:
70
71       •   Disable the layout in Dancer
72
73           You can do this by simply commenting (or removing) the "layout"
74           configuration in the config.yml file.
75
76       •   Use Template Toolkit template engine
77
78           Change the configuration of the template to Template Toolkit:
79
80               # in config.yml
81               template: "template_toolkit"
82
83       •   Tell the Template Toolkit engine who's your wrapper
84
85               # in config.yml
86               # ...
87               engines:
88                   template_toolkit:
89                       WRAPPER: layouts/main.tt
90
91       Done! Everything will work fine out of the box, including variables and
92       META variables.
93

EMBEDDED TEMPLATES

95       You can embed your templates in your script file, to get a self-
96       contained dancer application in one file (inspired by
97       <http://advent.perldancer.org/2011/3>).
98
99       To enable this:
100
101           # in app.pl
102           # ...
103           set engines => {
104               template_toolkit => {
105                   embedded_templates => 1,
106               },
107           };
108           set template => 'template_toolkit';
109
110       This feature requires Template::Provider::FromDATA. Put your templates
111       in the __DATA__ section, and start every template with
112       __${templatename}__.
113

USING TT'S WRAPPER STACK

115       This engine provides three additional methods to access the WRAPPER
116       stack of TemplateToolkit.
117
118   set_wrapper
119       Synopsis:
120
121           engine('template')->set_wrapper( inner => 'inner_layout.tt' );
122           engine('template')->set_wrapper( outer => 'outer_layout.tt' );
123           engine('template')->set_wrapper( 'only_layout.tt' );
124
125       The first two lines pushes/unshifts layout files to the wrapper array.
126       The third line overwrites the wrapper array with a single element.
127
128   unset_wrapper
129       Synopsis:
130
131           engine('template')->unset_wrapper('inner') # returns 'inner_layout.tt';
132           engine('template')->unset_wrapper('outer') # returns 'outer_layout.tt';
133
134       These lines pops/shifts layout files from the wrapper array and returns
135       the removed elements.
136
137   reset_wrapper
138       Synopsis:
139
140           engine('template')->reset_wrapper;
141
142       This method restores the wrapper array after a set_wrapper call.
143

SEE ALSO

145       Dancer, Template
146

AUTHOR

148       Dancer Core Developers
149
151       This software is copyright (c) 2010 by Alexis Sukrieh.
152
153       This is free software; you can redistribute it and/or modify it under
154       the same terms as the Perl 5 programming language system itself.
155
156
157
158perl v5.36.0                      2022-07-2D2ancer::Template::TemplateToolkit(3)
Impressum