1Template::Manual::PlugiUnsse(r3)Contributed Perl DocumenTteamtpiloante::Manual::Plugins(3)
2
3
4
6 Template::Manual::Plugins - Standard plugins
7
10 The following plugin modules are distributed with the Template Toolkit.
11 Some of the plugins interface to external modules (detailed below)
12 which should be downloaded from any CPAN site and installed before
13 using the plugin.
14
15 Autoformat
16
17 The Autoformat plugin is an interface to Damian Conway's Text::Autofor‐
18 mat Perl module which provides advanced text wrapping and formatting.
19 See Template::Plugin::Autoformat and Text::Autoformat for further
20 details.
21
22 [% USE autoformat(left=10, right=20) %]
23 [% autoformat(mytext) %] # call autoformat sub
24 [% mytext FILTER autoformat %] # or use autoformat filter
25
26 The Text::Autoformat module is available from CPAN:
27
28 http://www.cpan.org/modules/by-module/Text/
29
30 CGI
31
32 The CGI plugin is a wrapper around Lincoln Stein's
33 <lstein@genome.wi.mit.edu> CGI.pm module. The plugin is distributed
34 with the Template Toolkit (see Template::Plugin::CGI) and the CGI mod‐
35 ule itself is distributed with recent versions Perl, or is available
36 from CPAN.
37
38 [% USE CGI %]
39 [% CGI.param('param_name') %]
40 [% CGI.start_form %]
41 [% CGI.popup_menu( Name => 'color',
42 Values => [ 'Green', 'Brown' ] ) %]
43 [% CGI.end_form %]
44
45 Datafile
46
47 Provides an interface to data stored in a plain text file in a simple
48 delimited format. The first line in the file specifies field names
49 which should be delimiter by any non-word character sequence. Subse‐
50 quent lines define data using the same delimiter as in the first line.
51 Blank lines and comments (lines starting '#') are ignored. See Tem‐
52 plate::Plugin::Datafile for further details.
53
54 /tmp/mydata:
55
56 # define names for each field
57 id : email : name : tel
58 # here's the data
59 fred : fred@here.com : Fred Smith : 555-1234
60 bill : bill@here.com : Bill White : 555-5678
61
62 example:
63
64 [% USE userlist = datafile('/tmp/mydata') %]
65
66 [% FOREACH user = userlist %]
67 [% user.name %] ([% user.id %])
68 [% END %]
69
70 Date
71
72 The Date plugin provides an easy way to generate formatted time and
73 date strings by delegating to the POSIX strftime() routine. See Tem‐
74 plate::Plugin::Date and POSIX for further details.
75
76 [% USE date %]
77 [% date.format %] # current time/date
78
79 File last modified: [% date.format(template.modtime) %]
80
81 Directory
82
83 The Directory plugin provides a simple interface to a directory and the
84 files within it. See Template::Plugin::Directory for further details.
85
86 [% USE dir = Directory('/tmp') %]
87 [% FOREACH file = dir.files %]
88 # all the plain files in the directory
89 [% END %]
90 [% FOREACH file = dir.dirs %]
91 # all the sub-directories
92 [% END %]
93
94 DBI
95
96 The DBI plugin is no longer distributed as part of the Template Toolkit
97 (as of version 2.15). It is now available as a separate Template-Plug‐
98 in-DBI distribution from CPAN.
99
100 Dumper
101
102 The Dumper plugin provides an interface to the Data::Dumper module.
103 See Template::Plugin::Dumper and Data::Dumper for futher details.
104
105 [% USE dumper(indent=0, pad="<br>") %]
106 [% dumper.dump(myvar, yourvar) %]
107
108 File
109
110 The File plugin provides a general abstraction for files and can be
111 used to fetch information about specific files within a filesystem.
112 See Template::Plugin::File for further details.
113
114 [% USE File('/tmp/foo.html') %]
115 [% File.name %] # foo.html
116 [% File.dir %] # /tmp
117 [% File.mtime %] # modification time
118
119 Filter
120
121 This module implements a base class plugin which can be subclassed to
122 easily create your own modules that define and install new filters.
123
124 package MyOrg::Template::Plugin::MyFilter;
125
126 use Template::Plugin::Filter;
127 use base qw( Template::Plugin::Filter );
128
129 sub filter {
130 my ($self, $text) = @_;
131
132 # ...mungify $text...
133
134 return $text;
135 }
136
137 # now load it...
138 [% USE MyFilter %]
139
140 # ...and use the returned object as a filter
141 [% FILTER $MyFilter %]
142 ...
143 [% END %]
144
145 See Template::Plugin::Filter for further details.
146
147 Format
148
149 The Format plugin provides a simple way to format text according to a
150 printf()-like format. See Template::Plugin::Format for further
151 details.
152
153 [% USE bold = format('<b>%s</b>') %]
154 [% bold('Hello') %]
155
156 GD
157
158 The GD plugins are no longer part of the core Template Toolkit distri‐
159 bution. They are now available in a separate Template-GD distribution.
160
161 HTML
162
163 The HTML plugin is very basic, implementing a few useful methods for
164 generating HTML. It is likely to be extended in the future or inte‐
165 grated with a larger project to generate HTML elements in a generic way
166 (as discussed recently on the mod_perl mailing list).
167
168 [% USE HTML %]
169 [% HTML.escape("if (a < b && c > d) ..." %]
170 [% HTML.attributes(border => 1, cellpadding => 2) %]
171 [% HTML.element(table => { border => 1, cellpadding => 2 }) %]
172
173 See Template::Plugin::HTML for further details.
174
175 Iterator
176
177 The Iterator plugin provides a way to create a Template::Iterator
178 object to iterate over a data set. An iterator is created automati‐
179 cally by the FOREACH directive and is aliased to the 'loop' variable.
180 This plugin allows an iterator to be explicitly created with a given
181 name, or the default plugin name, 'iterator'. See Template::Plug‐
182 in::Iterator for further details.
183
184 [% USE iterator(list, args) %]
185
186 [% FOREACH item = iterator %]
187 [% '<ul>' IF iterator.first %]
188 <li>[% item %]
189 [% '</ul>' IF iterator.last %]
190 [% END %]
191
192 Pod
193
194 This plugin provides an interface to the Pod::POM module which parses
195 POD documents into an internal object model which can then be traversed
196 and presented through the Template Toolkit.
197
198 [% USE Pod(podfile) %]
199
200 [% FOREACH head1 = Pod.head1;
201 FOREACH head2 = head1/head2;
202 ...
203 END;
204 END
205 %]
206
207 String
208
209 The String plugin implements an object-oriented interface for manipu‐
210 lating strings. See Template::Plugin::String for further details.
211
212 [% USE String 'Hello' %]
213 [% String.append(' World') %]
214
215 [% msg = String.new('Another string') %]
216 [% msg.replace('string', 'text') %]
217
218 The string "[% msg %]" is [% msg.length %] characters long.
219
220 Table
221
222 The Table plugin allows you to format a list of data items into a vir‐
223 tual table by specifying a fixed number of rows or columns, with an
224 optional overlap. See Template::Plugin::Table for further details.
225
226 [% USE table(list, rows=10, overlap=1) %]
227
228 [% FOREACH item = table.col(3) %]
229 [% item %]
230 [% END %]
231
232 URL
233
234 The URL plugin provides a simple way of contructing URLs from a base
235 part and a variable set of parameters. See Template::Plugin::URL for
236 further details.
237
238 [% USE mycgi = url('/cgi-bin/bar.pl', debug=1) %]
239
240 [% mycgi %]
241 # ==> /cgi/bin/bar.pl?debug=1
242
243 [% mycgi(mode='submit') %]
244 # ==> /cgi/bin/bar.pl?mode=submit&debug=1
245
246 Wrap
247
248 The Wrap plugin uses the Text::Wrap module by David Muir Sharnoff
249 <muir@idiom.com> (with help from Tim Pierce and many many others) to
250 provide simple paragraph formatting. See Template::Plugin::Wrap and
251 Text::Wrap for further details.
252
253 [% USE wrap %]
254 [% wrap(mytext, 40, '* ', ' ') %] # use wrap sub
255 [% mytext FILTER wrap(40) -%] # or wrap FILTER
256
257 The Text::Wrap module is available from CPAN:
258
259 http://www.cpan.org/modules/by-module/Text/
260
261 XML::Style
262
263 This plugin defines a filter for performing simple stylesheet based
264 transformations of XML text.
265
266 [% USE xmlstyle
267 table = {
268 attributes = {
269 border = 0
270 cellpadding = 4
271 cellspacing = 1
272 }
273 }
274 %]
275
276 [% FILTER xmlstyle %]
277 <table>
278 <tr>
279 <td>Foo</td> <td>Bar</td> <td>Baz</td>
280 </tr>
281 </table>
282 [% END %]
283
284 See Template::Plugin::XML::Style for further details.
285
286 XML
287
288 The XML::DOM, XML::RSS, XML::Simple and XML::XPath plugins are no
289 longer distributed with the Template Toolkit as of version 2.15
290
291 They are now available in a separate Template-XML distribution.
292
294 Andy Wardley <abw@wardley.org>
295
296 <http://wardley.org/⎪http://wardley.org/>
297
299 Template Toolkit version 2.18, released on 09 February 2007.
300
302 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
303
304 This module is free software; you can redistribute it and/or modify it
305 under the same terms as Perl itself.
306
307
308
309perl v5.8.8 2007-02-09 Template::Manual::Plugins(3)