~ubuntu-branches/ubuntu/quantal/libtemplate-perl/quantal

« back to all changes in this revision

Viewing changes to html/misc/FAQ.html

  • Committer: Package Import Robot
  • Author(s): Benjamin Mako Hill
  • Date: 2012-04-08 19:06:29 UTC
  • mfrom: (0.7.1) (0.5.2) (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120408190629-wbcbs2ea39mex6lt
Tags: 2.24-1
* New upstream release (Closes: #664561)
* Bump Standards-Version to 3.9.3
* Changed to the short description to mention the term "Template
  Toolkit". (LP: #688836)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
 
4
<html>
 
5
  <head>
 
6
    <title>Template::FAQ</title>
 
7
    <link rel="stylesheet" type="text/css" href="../css/blue.css" title="Clear Blue">
 
8
    <link rel="alternate stylesheet" type="text/css" href="../css/orange.css" title="Clear Orange">
 
9
    <link rel="alternate stylesheet" type="text/css" href="../css/green.css" title="Clear Green">
 
10
    <link rel="alternate stylesheet" type="text/css" href="../css/purple.css" title="Clear Purple">
 
11
    <link rel="alternate stylesheet" type="text/css" href="../css/grey.css" title="Clear Grey">
 
12
    <!--[if IE 6]>
 
13
    <link rel="stylesheet" type="text/css" href="../css/ie6.css" />
 
14
    <![endif]-->
 
15
    <link rel="stylesheet" type="text/css" href="/css/print.css" media="print">
 
16
    <script type="text/javascript" src="../js/tt2.js"></script>
 
17
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
 
18
    <meta name="author" content="Andy Wardley">
 
19
  </head>
 
20
  <body id="body"> 
 
21
    <div id="layout">
 
22
        <div id="header">
 
23
          <a href="../index.html" id="logo" alt="" title="Click for the Home Page"><span class="alt">TT2 Home Page</span></a>
 
24
          <ul id="trail">
 
25
            <li><a href="..">???</a></li>
 
26
            <li class="last"><a href="../misc/FAQ.html">FAQ</a></li>
 
27
          </ul>
 
28
          <div class="controls">
 
29
            <a href="#" class="menu show" onclick="widescreen_off(); return false" title="Show Menu">
 
30
              <span class="about">Click to view the menu.  It's very nice.</span>
 
31
            </a>
 
32
            <a href="#" class="menu hide" onclick="widescreen_on();  return false" title="Hide Menu">
 
33
              <span class="about">Click to hide the menu and go all widescreen!</span>
 
34
            </a>
 
35
          
 
36
          <div class="pager">
 
37
            <span class="go back">Back<span class="about">Yeah right, I bet you've love to go back, but you can't.</span></span>
 
38
            <span class="go up">Up<span class="about">No, you can't go up.  You're silly to even think that you could.</span></span>
 
39
            <span class="go next">Next<span class="about">Since when did going to the next page become so important?</span></span>
 
40
          </div>
 
41
          </div>
 
42
          <h1 class="headline">Template::FAQ</h1>
 
43
          <h2 class="subhead">Frequently Asked Questions about the Template Toolkit</h1>
 
44
        
 
45
        </div>
 
46
        <div id="page">
 
47
          <div id="sidebar">
 
48
            <a href="../index.html" id="logo"></a>
 
49
            <div id="menu">
 
50
              <ul class="menu">
 
51
                <li class="l0 first"><a href="../manual/index.html">Manual</a></li>
 
52
                <li class="l0"><a href="../modules/index.html">Modules</a></li>
 
53
                <li class="l0"><a href="../tools/index.html">Tools</a></li>
 
54
                <li class="l0 last"><a href="../tutorial/index.html">Tutorial</a></li>
 
55
              </ul>
 
56
              <div class="foot"></div>
 
57
            </div>
 
58
          </div>
 
59
          <div id="content">
 
60
          <div class="section">
 
61
            <div class="head">
 
62
              <h1 id="contents" onclick="switch_section(this)" title="Click title to show/hide section content.">Contents</h1>
 
63
              <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
64
            </div>
 
65
            <div class="body">
 
66
              <ul class="toc">
 
67
                  <li class=""><a href="#DESCRIPTION">DESCRIPTION</a></li>
 
68
                  <li class=""><a href="#Template_Toolkit_Language">Template Toolkit Language</a></li>
 
69
                  <li class="sub"><a href="#section_Why_doesn_t_a_b_IF_c_work_as_expected_">Why doesn't [% a = b IF c %] work as expected?</a></li>
 
70
                  <li class="sub"><a href="#section_If_I_m_using_TT_to_write_out_a_TT_template_is_there_a_good_way_to_escape_and_">If I'm using TT to write out a TT template, is there a good way to escape [% and %]?</a></li>
 
71
                  <li class="sub"><a href="#section_How_do_I_iterate_over_a_hash_">How do I iterate over a hash?</a></li>
 
72
                  <li class=""><a href="#Plugins">Plugins</a></li>
 
73
                  <li class="sub"><a href="#section_How_do_I_get_the_Table_plugin_to_order_data_across_rather_than_down_">How do I get the Table plugin to order data across rather than down?</a></li>
 
74
                  <li class="sub"><a href="#section_Accessing_Cookies">Accessing Cookies</a></li>
 
75
                  <li class=""><a href="#Extending_the_Template_Toolkit">Extending the Template Toolkit</a></li>
 
76
                  <li class="sub"><a href="#section_Can_I_serve_templates_from_a_database_">Can I serve templates from a database?</a></li>
 
77
                  <li class="sub"><a href="#section_Can_I_fetch_templates_via_http_">Can I fetch templates via http?</a></li>
 
78
                  <li class=""><a href="#Miscellaneous">Miscellaneous</a></li>
 
79
                  <li class="sub"><a href="#section_How_can_I_find_out_the_name_of_the_main_template_being_processed_">How can I find out the name of the main template being processed?</a></li>
 
80
                  <li class="sub"><a href="#section_How_can_I_find_out_the_name_of_the_current_template_being_processed_">How can I find out the name of the current template being processed?</a></li>
 
81
                  <li class="sub"><a href="#section_How_do_I_print_the_modification_time_of_the_template_or_component_">How do I print the modification time of the template or component?</a></li>
 
82
                  <li class="sub"><a href="#section_How_can_I_configure_variables_on_a_per_request_basis_">How can I configure variables on a per-request basis?</a></li>
 
83
                  <li class=""><a href="#AUTHOR">AUTHOR</a></li>
 
84
                  <li class=""><a href="#COPYRIGHT">COPYRIGHT</a></li>
 
85
              
 
86
              </ul>
 
87
            </div>
 
88
          </div>
 
89
          
 
90
                <div class="pod">
 
91
            <div class="section">
 
92
              <div class="head">
 
93
                <h1 id="DESCRIPTION" onclick="switch_section(this)" title="Click title to show/hide section content.">DESCRIPTION</h1>
 
94
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
95
              </div>
 
96
              <div class="body">
 
97
                
 
98
              </div>
 
99
            </div>
 
100
            <div class="section">
 
101
              <div class="head">
 
102
                <h1 id="Template_Toolkit_Language" onclick="switch_section(this)" title="Click title to show/hide section content.">Template Toolkit Language</h1>
 
103
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
104
              </div>
 
105
              <div class="body">
 
106
                <div class="subsection">
 
107
                  <div class="head">
 
108
                    <h2 id="section_Why_doesn_t_a_b_IF_c_work_as_expected_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Why doesn't [% a = b IF c %] work as expected?</h2>
 
109
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
110
                  </div>
 
111
                  <div class="body">
 
112
                    <p>
 
113
                          Because the parser interprets it as
 
114
                        </p>
 
115
                        <pre><span class="tt">[% a = (b IF c) %]</span></pre>
 
116
                        <p>
 
117
                          Do this instead:
 
118
                        </p>
 
119
                        <pre><span class="tt">[% SET a = b IF c %]</span></pre>
 
120
                  </div>
 
121
                </div>    <div class="subsection">
 
122
                  <div class="head">
 
123
                    <h2 id="section_If_I_m_using_TT_to_write_out_a_TT_template_is_there_a_good_way_to_escape_and_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">If I'm using TT to write out a TT template, is there a good way to escape [% and %]?</h2>
 
124
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
125
                  </div>
 
126
                  <div class="body">
 
127
                    <p>
 
128
                          You can do this: [% stag = "[\%" etag = "%\]" %] and then: [% stag;
 
129
                          'hello'; etag %]
 
130
                        </p>
 
131
                        <p>
 
132
                          Or something like:
 
133
                        </p>
 
134
                        <pre><span class="tt">[% TAGS [- -] %]</span>
 
135
[- INCLUDE foo -]   # is a directive
 
136
<span class="tt">[% INCLUDE foo %]</span>   # not a directive, just plain text, passed through</pre>
 
137
                  </div>
 
138
                </div>    <div class="subsection">
 
139
                  <div class="head">
 
140
                    <h2 id="section_How_do_I_iterate_over_a_hash_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How do I iterate over a hash?</h2>
 
141
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
142
                  </div>
 
143
                  <div class="body">
 
144
                    <p>
 
145
                          This is covered in the <a
 
146
                          href="#section_VMethods">Template::Manual::VMethods</a> section of the
 
147
                          manual page. A list of all the keys that are in the hash can be obtained
 
148
                          with the 'keys' virtual method. You can then iterate over that list and
 
149
                          by looking up each key in turn get the value.
 
150
                        </p>
 
151
                        <pre><span class="tt">[% FOREACH key = product.keys %]</span>
 
152
   <span class="tt">[% key %]</span> =&gt; <span class="tt">[% product.$key %]</span>
 
153
<span class="tt">[% END %]</span></pre>
 
154
                  </div>
 
155
                </div>
 
156
              </div>
 
157
            </div>
 
158
            <div class="section">
 
159
              <div class="head">
 
160
                <h1 id="Plugins" onclick="switch_section(this)" title="Click title to show/hide section content.">Plugins</h1>
 
161
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
162
              </div>
 
163
              <div class="body">
 
164
                <div class="subsection">
 
165
                  <div class="head">
 
166
                    <h2 id="section_How_do_I_get_the_Table_plugin_to_order_data_across_rather_than_down_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How do I get the Table plugin to order data across rather than down?</h2>
 
167
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
168
                  </div>
 
169
                  <div class="body">
 
170
                    <p>
 
171
                          Order the data into rows:
 
172
                        </p>
 
173
                        <pre> Steve     Karen     Jeff
 
174
 Brooklyn  Nantucket Fairfax
 
175
 NY        MA        VA
 
176
 
 
177
<span class="tt">[% USE table(data, rows=3) %]</span>
 
178
 
 
179
Then ask for each column
 
180
 
 
181
<span class="tt">[% FOREACH column = table.cols %]</span>
 
182
 
 
183
And then print each item in the column going across the output rows
 
184
 
 
185
<span class="tt">[% FOREACH item = column %]</span>
 
186
&lt;td&gt;<span class="tt">[% item %]</span>&lt;/td&gt;
 
187
<span class="tt">[% END %]</span></pre>
 
188
                  </div>
 
189
                </div>    <div class="subsection">
 
190
                  <div class="head">
 
191
                    <h2 id="section_Accessing_Cookies" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Accessing Cookies</h2>
 
192
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
193
                  </div>
 
194
                  <div class="body">
 
195
                    <p>
 
196
                          Jeff Boes &lt;jboes@nexcerpt.com&gt; asks:
 
197
                        </p>
 
198
                        <pre>Does anyone have a quick-n-dirty approach to accessing 
 
199
cookies from templates? </pre>
 
200
                        <p>
 
201
                          Jonas Liljegren answers:
 
202
                        </p>
 
203
                        <pre><span class="tt">[% USE CGI %]</span>
 
204
 
 
205
&lt;p&gt;The value is <span class="tt">[% CGI.cookie('cookie_name') | html %]</span></pre>
 
206
                  </div>
 
207
                </div>
 
208
              </div>
 
209
            </div>
 
210
            <div class="section">
 
211
              <div class="head">
 
212
                <h1 id="Extending_the_Template_Toolkit" onclick="switch_section(this)" title="Click title to show/hide section content.">Extending the Template Toolkit</h1>
 
213
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
214
              </div>
 
215
              <div class="body">
 
216
                <div class="subsection">
 
217
                  <div class="head">
 
218
                    <h2 id="section_Can_I_serve_templates_from_a_database_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Can I serve templates from a database?</h2>
 
219
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
220
                  </div>
 
221
                  <div class="body">
 
222
                    <p>
 
223
                          Short answer: yes, Chris Nandor has done this for Slash. You need to
 
224
                          subclass Template::Provider. See the mailing list archives for further
 
225
                          info.
 
226
                        </p>
 
227
                  </div>
 
228
                </div>    <div class="subsection">
 
229
                  <div class="head">
 
230
                    <h2 id="section_Can_I_fetch_templates_via_http_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">Can I fetch templates via http?</h2>
 
231
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
232
                  </div>
 
233
                  <div class="body">
 
234
                    <p>
 
235
                          To do the job properly, you should sublcass Template::Provider to
 
236
                          Template::Provider::HTTP and use a PREFIX_MAP option to bind the 'http'
 
237
                          template prefix to that particular provider (you may want to go digging
 
238
                          around in the <i>Changes</i> file around version 2.01 for more info on
 
239
                          PREFIX_MAP - it may not be properly documented anywhere else...yet!).
 
240
                          e.g. (untested due to lack of existing HTTP Provider - patches welcome!).
 
241
                        </p>
 
242
                        <pre>use Template::Provider::HTTP;</pre>
 
243
                        <pre>my $file = Template::Provider( INCLUDE_PATH =&gt; [...] );
 
244
my $http = Template::Provider::HTTP-&gt;new(...);
 
245
my $tt2  = Template-&gt;new({
 
246
LOAD_TEMPLATES =&gt; [ $file, $http ],
 
247
PREFIX_MAP =&gt; {
 
248
    file    =&gt; '0',    # file:foo.html
 
249
    http    =&gt; '1',    # http:foo.html
 
250
    default =&gt; '0',    # foo.html =&gt; file:foo.html
 
251
}
 
252
});</pre>
 
253
                        <p>
 
254
                          Now a template specified as:
 
255
                        </p>
 
256
                        <pre><span class="tt">[% INCLUDE foo %]</span></pre>
 
257
                        <p>
 
258
                          will be served by the 'file' provider (the default). Otherwise you can
 
259
                          explicitly add a prefix:
 
260
                        </p>
 
261
                        <pre><span class="tt">[% INCLUDE file:foo.html %]</span>
 
262
<span class="tt">[% INCLUDE http:foo.html %]</span>
 
263
<span class="tt">[% INCLUDE http://www.xyz.com/tt2/header.tt2 %]</span></pre>
 
264
                        <p>
 
265
                          This same principal can be used to create a DBI template provider. e.g.
 
266
                        </p>
 
267
                        <pre><span class="tt">[% INCLUDE dbi:foo.html %]</span></pre>
 
268
                        <p>
 
269
                          But similarly, alas, we don't yet have a DBI provider as part of the
 
270
                          Template Toolkit. There has been some talk on the mailing list about
 
271
                          efforts to develop DBI and/or HTTP providers but as yet no-one has
 
272
                          stepped forward to take up the challenge...
 
273
                        </p>
 
274
                        <p>
 
275
                          In the mean time, Craig's post from the mailing list has some useful
 
276
                          pointers on how to acheive this using existing modules:
 
277
                        </p>
 
278
                        <pre>To: Adam Theo &lt;adamtheo@theoretic.com&gt; 
 
279
From: Craig Barratt &lt;craig@arraycomm.com&gt;
 
280
Date: Fri, 18 May 2001 17:06:59 -0700
 
281
 
 
282
&gt; i was wondering if there is anyway to fetch a file using http:// or
 
283
&gt; ftp:// and include that?
 
284
 
 
285
Here's one way.  Set the LOAD_PERL option:
 
286
 
 
287
    use Template;
 
288
 
 
289
    my $template = Template-&gt;new({  
 
290
        LOAD_PERL =&gt; 1
 
291
    });  
 
292
    $template-&gt;process("example.tt", { stdout =&gt; *STDOUT })
 
293
                     || die $template-&gt;error();
 
294
 
 
295
and then use LWP::UserAgent and HTTP::Request:
 
296
 
 
297
    <span class="tt">[% 
 
298
        USE ua = LWP.UserAgent; 
 
299
        ua.proxy("http", "http://your_proxy/");
 
300
        USE req = HTTP.Request("GET", "http://www.cpan.org");
 
301
        ua.request(req).content;
 
302
    -%]</span>
 
303
 
 
304
For FTP use Net::FTP:
 
305
 
 
306
    <span class="tt">[%   
 
307
        USE ftp = Net.FTP("ftp.cpan.org");
 
308
        x = ftp.login("anonymous", "me@here.there");
 
309
        x = ftp.cwd("/");
 
310
        x = ftp.get("welcome.msg", stdout);
 
311
        x = ftp.quit;
 
312
    -%]</span>
 
313
 
 
314
Normally ftp.get would write the file into the current directory.
 
315
Instead we pass stdout as a second argument so that it is written
 
316
to stdout.  We set stdout to STDOUT in the variables we pass to
 
317
process. 
 
318
 
 
319
Craig</pre>
 
320
                  </div>
 
321
                </div>
 
322
              </div>
 
323
            </div>
 
324
            <div class="section">
 
325
              <div class="head">
 
326
                <h1 id="Miscellaneous" onclick="switch_section(this)" title="Click title to show/hide section content.">Miscellaneous</h1>
 
327
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
328
              </div>
 
329
              <div class="body">
 
330
                <div class="subsection">
 
331
                  <div class="head">
 
332
                    <h2 id="section_How_can_I_find_out_the_name_of_the_main_template_being_processed_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How can I find out the name of the main template being processed?</h2>
 
333
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
334
                  </div>
 
335
                  <div class="body">
 
336
                    <p>
 
337
                          The <code>template</code> variable contains a reference to the
 
338
                          Template::Document object for the main template you're processing (i.e.
 
339
                          the one provided as the first argument to the Template process() method).
 
340
                          The <code>name</code> method returns its name.
 
341
                        </p>
 
342
                        <pre><span class="tt">[% template.name %]</span>     # e.g. index.html</pre>
 
343
                  </div>
 
344
                </div>    <div class="subsection">
 
345
                  <div class="head">
 
346
                    <h2 id="section_How_can_I_find_out_the_name_of_the_current_template_being_processed_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How can I find out the name of the current template being processed?</h2>
 
347
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
348
                  </div>
 
349
                  <div class="body">
 
350
                    <p>
 
351
                          The <code>template</code> variable always references the <i>main</i>
 
352
                          template being processed. So even if you call [% INCLUDE header %], and
 
353
                          that calls [% INCLUDE menu %], the <code>template</code> variable will be
 
354
                          unchanged.
 
355
                        </p>
 
356
                        <p>
 
357
                          index.html:
 
358
                        </p>
 
359
                        <pre><span class="tt">[% template.name  %]</span>     # index.html
 
360
<span class="tt">[% INCLUDE header %]</span></pre>
 
361
                        <p>
 
362
                          header:
 
363
                        </p>
 
364
                        <pre><span class="tt">[% template.name  %]</span>     # index.html
 
365
<span class="tt">[% INCLUDE menu   %]</span></pre>
 
366
                        <p>
 
367
                          menu:
 
368
                        </p>
 
369
                        <pre><span class="tt">[% template.name  %]</span>     # index.html</pre>
 
370
                        <p>
 
371
                          In constrast, the <code>component</code> variable always references the
 
372
                          <i>current</i> template being processed.
 
373
                        </p>
 
374
                        <p>
 
375
                          index.html
 
376
                        </p>
 
377
                        <pre><span class="tt">[% component.name %]</span>     # index.html
 
378
<span class="tt">[% INCLUDE header %]</span></pre>
 
379
                        <p>
 
380
                          header:
 
381
                        </p>
 
382
                        <pre><span class="tt">[% component.name %]</span>     # header
 
383
<span class="tt">[% INCLUDE menu   %]</span></pre>
 
384
                        <p>
 
385
                          menu:
 
386
                        </p>
 
387
                        <pre><span class="tt">[% component.name  %]</span>     # menu</pre>
 
388
                  </div>
 
389
                </div>    <div class="subsection">
 
390
                  <div class="head">
 
391
                    <h2 id="section_How_do_I_print_the_modification_time_of_the_template_or_component_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How do I print the modification time of the template or component?</h2>
 
392
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
393
                  </div>
 
394
                  <div class="body">
 
395
                    <p>
 
396
                          The <code>template</code> and <code>component</code> variables reference
 
397
                          the main template and the current template being processed (see previous
 
398
                          questions). The <code>modtime</code> method returns the modification time
 
399
                          of the corresponding template file as a number of seconds since the Unix
 
400
                          epoch (00:00:00 GMT 1st January 1970).
 
401
                        </p>
 
402
                        <p>
 
403
                          This number doesn't mean much to anyone (except perhaps serious Unix
 
404
                          geeks) so you'll probably want to use the Date plugin to format it for
 
405
                          human consumption.
 
406
                        </p>
 
407
                        <pre><span class="tt">[% USE Date %]</span></pre>
 
408
                        <pre><span class="tt">[% template.name %]</span> last modified <span class="tt">[% Date.format(template.modtime) %]</span></pre>
 
409
                  </div>
 
410
                </div>    <div class="subsection">
 
411
                  <div class="head">
 
412
                    <h2 id="section_How_can_I_configure_variables_on_a_per_request_basis_" onclick="switch_subsection(this)" title="Click title to show/hide sub-section content.">How can I configure variables on a per-request basis?</h2>
 
413
                    <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
414
                  </div>
 
415
                  <div class="body">
 
416
                    <p>
 
417
                          One easy way to acheive this is to define a single PRE_PROCESS template
 
418
                          which loads in other configuration files based on variables defined or
 
419
                          other conditions.
 
420
                        </p>
 
421
                        <p>
 
422
                          For example, my setup usually looks something like this:
 
423
                        </p>
 
424
                        <pre>PRE_PROCESS =&gt; 'config/main'</pre>
 
425
                        <p>
 
426
                          config/main:
 
427
                        </p>
 
428
                        <pre>[%  DEFAULT  style   = 'text'
 
429
             section =  template.section or 'home';</pre>
 
430
                        <pre>    PROCESS  config/site
 
431
          +  config/urls
 
432
          +  config/macros
 
433
          + "config/style/$style"
 
434
          + "config/section/$section"
 
435
          + ...
 
436
%]</pre>
 
437
                        <p>
 
438
                          This allows me to set a single 'style' variable to control which config
 
439
                          file gets pre-processed to set my various style options (colours, img
 
440
                          paths, etc). For example:
 
441
                        </p>
 
442
                        <p>
 
443
                          config/style/basic:
 
444
                        </p>
 
445
                        <pre>[%  style = {
 
446
    name = style    # save existing 'style' var as 'style.name'</pre>
 
447
                        <pre># define various other style variables....
 
448
    col = {
 
449
    back =&gt; '#ffffff'
 
450
    text =&gt; '#000000'
 
451
    # ...etc...
 
452
}</pre>
 
453
                        <pre>logo = {
 
454
    # ...etc...
 
455
}</pre>
 
456
                        <pre>    # ...etc...
 
457
}
 
458
%]</pre>
 
459
                        <p>
 
460
                          Each source template can declare which section it's in via a META
 
461
                          directive:
 
462
                        </p>
 
463
                        <pre><span class="tt">[% META
 
464
 title   = 'General Information'
 
465
 section = 'info'
 
466
%]</span></pre>
 
467
                        <pre>...</pre>
 
468
                        <p>
 
469
                          This controls which section configuration file gets loaded to set various
 
470
                          other variables for defining the section title, menu, etc.
 
471
                        </p>
 
472
                        <p>
 
473
                          config/section/info:
 
474
                        </p>
 
475
                        <pre><span class="tt">[%  section = {
 
476
        name   = section  # save 'section' var as 'section.name'
 
477
        title  = 'Information'
 
478
        menu   = [ ... ]
 
479
        # ...etc...
 
480
    }
 
481
%]</span></pre>
 
482
                        <p>
 
483
                          This illustrates the basic principal but you can extend it to perform
 
484
                          pretty much any kind of per-document initialisation that you require.
 
485
                        </p>
 
486
                  </div>
 
487
                </div>
 
488
              </div>
 
489
            </div>
 
490
            <div class="section">
 
491
              <div class="head">
 
492
                <h1 id="AUTHOR" onclick="switch_section(this)" title="Click title to show/hide section content.">AUTHOR</h1>
 
493
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
494
              </div>
 
495
              <div class="body">
 
496
                <p>
 
497
                      Andy Wardley &lt;abw@wardley.org&gt; <a
 
498
                      href="http://wardley.org/">http://wardley.org/</a>
 
499
                    </p>
 
500
              </div>
 
501
            </div>
 
502
            <div class="section">
 
503
              <div class="head">
 
504
                <h1 id="COPYRIGHT" onclick="switch_section(this)" title="Click title to show/hide section content.">COPYRIGHT</h1>
 
505
                <a href="#body" class="top" title="Back up to the top of the page" >Top</a>
 
506
              </div>
 
507
              <div class="body">
 
508
                <p>
 
509
                      Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
 
510
                    </p>
 
511
                    <p>
 
512
                      This module is free software; you can redistribute it and/or modify it
 
513
                      under the same terms as Perl itself.
 
514
                    </p>
 
515
              </div>
 
516
            </div>
 
517
            
 
518
            </div></div>
 
519
          <br class="clear" />
 
520
          <div class="pageinfo">
 
521
            /misc/FAQ.html last modified 10:38:14 01-Jun-2007
 
522
          </div>
 
523
        </div>
 
524
        
 
525
        <div id="footer">
 
526
          <a href="http://opensource.org/" class="osi"></a>
 
527
          <div class="controls">
 
528
          <div class="pager">
 
529
            <span class="go back">Back<span class="about"></span></span>
 
530
            <span class="go up">Up<span class="about"></span></span>
 
531
            <span class="go next">Next<span class="about"></span></span>
 
532
          </div>
 
533
          </div>
 
534
          <div class="copyright">
 
535
            Copyright &copy; 1996-2007 <a href="http://wardley.org/">Andy Wardley</a>.  All Rights Reserved.
 
536
          </div>
 
537
          <div class="licence">
 
538
            The <a href="http://template-toolkit.org/">Template Toolkit</a> is <a href="http://opensource.org/">Open Source</a> software.
 
539
            You can redistribute and/or modify it under the terms of the <a href="http://www.opensource.org/licenses/gpl-license.php">GNU Public Licence</a>
 
540
            or the <a href="http://www.opensource.org/licenses/artistic-license.php">Perl Artistic Licence</a>.
 
541
          </div>
 
542
        </div>
 
543
        <div id="palette">
 
544
          <ul>
 
545
            <li class="first"><a href="#" class="blue" onclick="set_style('Clear Blue')"></a></li>
 
546
            <li><a href="#" class="orange" onclick="set_style('Clear Orange')"></a></li>
 
547
            <li><a href="#" class="green" onclick="set_style('Clear Green')"></a></li>
 
548
            <li><a href="#" class="purple" onclick="set_style('Clear Purple')"></a></li>
 
549
            <li><a href="#" class="grey" onclick="set_style('Clear Grey')"></a></li>
 
550
          </ul>
 
551
        </div>
 
552
    </div>  </body>
 
553
</html>