1Template::Toolkit::SimpUlsee(r3)Contributed Perl DocumenTteamtpiloante::Toolkit::Simple(3)
2
3
4

NAME

6       Template::Toolkit::Simple - A Simple Interface to Template Toolkit
7

SYNOPSIS

9             use Template::Toolkit::Simple;
10
11             print tt
12                 ->path(['./', 'template/'])
13                 ->data('values.yaml')
14                 ->post_chomp
15                 ->render('foo.tt');
16
17       or from the command line:
18
19             tt-render --path=./:template/ --data=values.yaml --post-chomp foo.tt
20

DESCRIPTION

22       Template Toolkit is the best Perl template framework. The only problem
23       with it is that using it for simple stuff is a little bit cumbersome.
24       Also there is no good utility for using it from the command line.
25
26       This module is a simple wrapper around Template Toolkit. It exports a
27       function called "tt" which returns a new Template::Toolkit::Simple
28       object. The object supports method calls for setting all the Template
29       Toolkit options.
30
31       This module also installs a program called "tt-render" which you can
32       use from the command line to render templates with all the power of the
33       Perl object. All of the object methods become command line arguments in
34       the command line version.
35

COMMAND LINE USAGE

37       This command renders the named file and prints the output to STDOUT. If
38       an error occurs, it is printed to STDERR.
39
40           tt-render [template-options] file-name
41

TEMPLATE PATH

43       When using Template::Toolkit::Simple or "tt-render", the most common
44       parameters you will use are the main template file name and the
45       directory of supporting templates. As a convenience, you can specify
46       these together.
47
48       This:
49
50           tt->render('foo//bar/baz.tt');
51           > tt-render foo//bar/baz.tt  # command line version
52
53       is the same as:
54
55           tt->include_path('foo/')->render('bar/baz.tt');
56           > tt-render --include_path=foo/ bar/baz.tt  # command line version
57
58       Just use a double slash to separate the path from the template. This is
59       extra handy on the command line, because (at least in Bash) tab
60       completion still works after you specify the '//'.
61

EXPORTED SUBROUTINES

63       tt  Simply returns a new Template::Toolkit::Simple object. This is
64           Simple sugar for:
65
66               Template::Toolkit::Simple->new();
67
68           It takes no parameters.
69

METHODS

71       This section describes the methods that are not option setting methods.
72       Those methods are described below.
73
74       new()
75           Return a new Template::Toolkit::Simple object. Takes no parameters.
76
77       render($template, $data);
78           This is the method that actually renders the template. It is
79           similar to the Template Toolkit "process" method, except that it
80           actually returns the template result as a string. It returns undef
81           if an error occurs.
82
83           The $data field is optional and can be set with the "data" method.
84
85           If you need more control, see the process command below:
86
87       process($template, $data, $output, %options);
88           This command is simply a proxy to the Template Toolkit "process"
89           command. All the parameters you give it are passed to the real
90           "process" command and the result is returned. See Template for more
91           information.
92
93       output($filepath)
94           Specify a filepath to print the template result to.
95
96       error()
97           This method is a proxy to the Template Toolkit "error" method. It
98           returns the error message if there was an error.
99

OPTION METHODS

101       All of the Template Toolkit options are available as methods to
102       Template::Toolkit::Simple objects, and also as command line options to
103       the "tt- render" command.
104
105       For example, the "POST_CHOMP" options is available in the following
106       ways:
107
108           tt->post_chomp      # turn POST_CHOMP on
109           tt->post_chomp(1)   # turn POST_CHOMP on
110           tt->post_chomp(0)   # turn POST_CHOMP off
111
112           --post_chomp        # turn POST_CHOMP on
113           --post-chomp        # same. use - instead of _
114           --post_chomp=1      # turn POST_CHOMP on
115           --post_chomp=0      # turn POST_CHOMP off
116
117       If the method functionality is not explained below, please refer to
118       Template.
119
120       "config($file_name || $hash)"
121           If you have a common set of Template Toolkit options stored in a
122           file, you can use this method to read and parse the file, and set
123           the appropriate options.
124
125           The currently supported file formats are YAML, JSON and XML. The
126           format is determined by the file extension, so use the appropriate
127           one. Note that XML::Simple is used to parse XML files and JSON::XS
128           is used to parse JSON files.
129
130       "data($file_name || $hash)"
131           Most templates use a hash object of data to access values while
132           rendering. You can specify this data in a file or with a hash
133           reference.
134
135           The currently supported file formats are YAML, JSON and XML. The
136           format is determined by the file extension, so use the appropriate
137           one. Note the XML::Simple is used to parse XML files.
138
139       "include_path($template_directories)"
140           Default is undef
141
142           This method allows you to specify the directories that are searched
143           to find templates. You can specify this as a string containing a
144           single directory, an array ref of strings containing directory
145           names, or as a string containing multiple directories separated by
146           ':'.
147
148       "path()"
149           Default is undef
150
151           This is a shorter name for "include_path". It does the exact same
152           thing.
153
154       "start_tag()"
155           Default is '[%'
156
157       "end_tag()"
158           Default is '%]'
159
160       "tag_style()"
161           Default is 'template'
162
163       "pre_chomp()"
164           Default is 0
165
166       "post_chomp()"
167           Default is 0
168
169       "trim()"
170           Default is 0
171
172       "interpolate()"
173           Default is 0
174
175       "anycase()"
176           Default is 0
177
178       "delimiter()"
179           Default is ':'
180
181       "absolute()"
182           Default is 0
183
184       "relative()"
185           Default is 0
186
187       "strict()"
188           Default is 0
189
190       "default()"
191           Default is undef
192
193       "blocks()"
194           Default is undef
195
196       "auto_reset()"
197           Default is 1
198
199       "recursion()"
200           Default is 0
201
202       "eval_perl()"
203           Default is 0
204
205       "pre_process()"
206           Default is undef
207
208       "post_process()"
209           Default is undef
210
211       "process_template()"
212           Default is undef
213
214           This is a proxy to the Template Toolkit PROCESS option. The
215           "process" method is used to actually process a template.
216
217       "error_template()"
218           Default is undef
219
220           This is a proxy to the Template Toolkit ERROR option. The "error()"
221           method returns the error message on a failure.
222
223       "debug()"
224           Default is 0
225
226       "cache_size()"
227           Default is undef
228
229       "compile_ext()"
230           Default is undef
231
232       "compile_dir()"
233           Default is undef
234
235       "encoding()"
236           Default is 'utf8'
237

AUTHOR

239       Ingy döt Net <ingy@cpan.org>
240
242       Copyright 2008-2014. Ingy döt Net.
243
244       This program is free software; you can redistribute it and/or modify it
245       under the same terms as Perl itself.
246
247       See <http://www.perl.com/perl/misc/Artistic.html>
248
249
250
251perl v5.28.1                      2014-12-09      Template::Toolkit::Simple(3)
Impressum