home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Directives.pod < prev    next >
Encoding:
Text File  |  2004-01-30  |  59.4 KB  |  2,180 lines

  1. #============================================================= -*-perl-*-
  2. #
  3. # Template::Manual::Directives
  4. #
  5. # DESCRIPTION
  6. #   This section provides a reference of all Template Toolkit
  7. #   directives, complete with examples of use.
  8. #
  9. # AUTHOR
  10. #   Andy Wardley  <abw@andywardley.com>
  11. #
  12. # COPYRIGHT
  13. #   Copyright (C) 1996-2001 Andy Wardley.  All Rights Reserved.
  14. #   Copyright (C) 1998-2001 Canon Research Centre Europe Ltd.
  15. #
  16. #   This module is free software; you can redistribute it and/or
  17. #   modify it under the same terms as Perl itself.
  18. #
  19. # REVISION
  20. #   
  21. #
  22. #========================================================================
  23.  
  24.  
  25. #------------------------------------------------------------------------
  26. # IMPORTANT NOTE
  27. #   This documentation is generated automatically from source
  28. #   templates.  Any changes you make here may be lost.
  29. #   The 'docsrc' documentation source bundle is available for download
  30. #   from http://www.template-toolkit.org/docs.html and contains all
  31. #   the source templates, XML files, scripts, etc., from which the
  32. #   documentation for the Template Toolkit is built.
  33. #------------------------------------------------------------------------
  34.  
  35. =head1 NAME
  36.  
  37. Template::Manual::Directives - Template directives
  38.  
  39. =head1 DESCRIPTION
  40.  
  41. This section provides a reference of all Template Toolkit directives,
  42. complete with examples of use.
  43.  
  44. =head2 Accessing and Updating Template Variables
  45.  
  46. =over 4
  47.  
  48.  
  49. =item GET
  50.  
  51. The GET directive retrieves and outputs the value of the named variable.
  52.  
  53.     [% GET foo %]
  54.  
  55. The GET keyword is optional.  A variable can be specified in a directive
  56. tag by itself.
  57.  
  58.     [% foo %]
  59.  
  60. The variable can have an unlimited number of elements, each separated
  61. by a dot '.'.  Each element can have arguments specified within
  62. parentheses.
  63.  
  64.     [% foo %]
  65.     [% bar.baz %]
  66.     [% biz.baz(10) %]
  67.     ...etc...
  68.  
  69. See L<Template::Manual::Variables> for a full discussion on template
  70. variables.
  71.  
  72. You can also specify expressions using the logical (and, or, not, ?:) and
  73. mathematic operators (+ - * / % mod div).
  74.  
  75.     [% template.title or default.title %]
  76.  
  77.     [% score * 100 %]
  78.  
  79.     [% order.nitems ? checkout(order.total) : 'no items' %]
  80.  
  81. The 'div' operator returns the integer result of division.  Both '%' and 
  82. 'mod' return the modulus (i.e. remainder) of division.  'mod' is provided
  83. as an alias for '%' for backwards compatibility with version 1.
  84.  
  85.     [% 15 / 6 %]        # 2.5
  86.     [% 15 div 6 %]        # 2
  87.     [% 15 mod 6 %]        # 3
  88.  
  89.  
  90.  
  91. =item CALL
  92.  
  93. The CALL directive is similar to GET in evaluating the variable named,
  94. but doesn't print the result returned.  This can be useful when a
  95. variable is bound to a sub-routine or object method which you want to
  96. call but aren't interested in the value returned.
  97.  
  98.     [% CALL dbi.disconnect %]
  99.  
  100.     [% CALL inc_page_counter(page_count) %]
  101.  
  102.  
  103.  
  104.  
  105. =item SET
  106.  
  107. The SET directive allows you to assign new values to existing variables
  108. or create new temporary variables.
  109.  
  110.     [% SET title = 'Hello World' %]
  111.  
  112. The SET keyword is also optional.
  113.    
  114.     [% title = 'Hello World' %]
  115.  
  116. Variables may be assigned the values of other variables, unquoted
  117. numbers (digits), literal text ('single quotes') or quoted text
  118. ("double quotes").  In the latter case, any variable references within
  119. the text will be interpolated when the string is evaluated.  Variables
  120. should be prefixed by '$', using curly braces to explicitly scope
  121. the variable name where necessary.
  122.  
  123.     [% foo  = 'Foo'  %]               # literal value 'Foo'
  124.     [% bar  =  foo   %]               # value of variable 'foo'
  125.     [% cost = '$100' %]               # literal value '$100'
  126.     [% item = "$bar: ${cost}.00" %]   # value "Foo: $100.00"
  127.  
  128. Multiple variables may be assigned in the same directive and are 
  129. evaluated in the order specified.  Thus, the above could have been 
  130. written:
  131.  
  132.     [% foo  = 'Foo'
  133.        bar  = foo
  134.        cost = '$100'
  135.        item = "$bar: ${cost}.00"
  136.     %]
  137.  
  138. Simple expressions can also be used, as per GET.
  139.  
  140.     [% ten    = 10 
  141.        twenty = 20
  142.        thirty = twenty + ten
  143.        forty  = 2 * twenty 
  144.        fifty  = 100 div 2
  145.        six    = twenty mod 7
  146.     %]
  147.  
  148. You can concatenate strings together using the ' _ ' operator.  In Perl 5,
  149. the '.' is used for string concatenation, but in Perl 6, as in the Template
  150. Toolkit, the '.' will be used as the method calling operator and ' _ ' will
  151. be used for string concatenation.  Note that the operator must be 
  152. specified with surrounding whitespace which, as Larry says, is construed as
  153. a feature:
  154.  
  155.     [% copyright = '(C) Copyright' _ year _ ' ' _ author %]
  156.  
  157. You can, of course, achieve a similar effect with double quoted string 
  158. interpolation.
  159.  
  160.     [% copyright = "(C) Copyright $year $author" %]
  161.  
  162.  
  163.  
  164.  
  165.  
  166. =item DEFAULT
  167.  
  168. The DEFAULT directive is similar to SET but only updates variables 
  169. that are currently undefined or have no "true" value (in the Perl
  170. sense).
  171.  
  172.     [% DEFAULT
  173.        name = 'John Doe'
  174.        id   = 'jdoe'
  175.     %]
  176.  
  177. This can be particularly useful in common template components to
  178. ensure that some sensible default are provided for otherwise 
  179. undefined variables.
  180.  
  181.     [% DEFAULT 
  182.        title = 'Hello World'
  183.        bgcol = '#ffffff'
  184.     %]
  185.     <html>
  186.     <head>
  187.     <title>[% title %]</title>
  188.     </head>
  189.  
  190.     <body bgcolor="[% bgcol %]">
  191.  
  192.  
  193. =back
  194.  
  195. =head2 Processing Other Template Files and Blocks
  196.  
  197. =over 4
  198.  
  199.  
  200. =item INSERT
  201.  
  202. The INSERT directive is used to insert the contents of an external file
  203. at the current position.
  204.  
  205.     [% INSERT myfile %]
  206.  
  207. No attempt to parse or process the file is made.  The contents,
  208. possibly including any embedded template directives, are inserted
  209. intact.
  210.  
  211. The filename specified should be relative to one of the INCLUDE_PATH
  212. directories.  Absolute (i.e. starting with C</>) and relative
  213. (i.e. starting with C<.>) filenames may be used if the ABSOLUTE and
  214. RELATIVE options are set, respectively.  Both these options are
  215. disabled by default.
  216.  
  217.     my $template = Template->new({
  218.     INCLUDE_PATH => '/here:/there',
  219.     });
  220.  
  221.     $template->process('myfile');
  222.  
  223. 'myfile':
  224.  
  225.     [% INSERT foo %]        # looks for /here/foo then /there/foo
  226.     [% INSERT /etc/passwd %]    # file error: ABSOLUTE not set
  227.     [% INSERT ../secret %]    # file error: RELATIVE not set
  228.  
  229. For convenience, the filename does not need to be quoted as long as it
  230. contains only alphanumeric characters, underscores, dots or forward
  231. slashes.  Names containing any other characters should be quoted.
  232.  
  233.     [% INSERT misc/legalese.txt            %]
  234.     [% INSERT 'dos98/Program Files/stupid' %]
  235.  
  236. To evaluate a variable to specify a filename, you should explicitly
  237. prefix it with a '$' or use double-quoted string interpolation.
  238.  
  239.     [% language = 'en'
  240.        legalese = 'misc/legalese.txt' 
  241.     %]
  242.  
  243.     [% INSERT $legalese %]        # 'misc/legalese.txt'
  244.     [% INSERT "$language/$legalese" %]  # 'en/misc/legalese.txt'
  245.  
  246. Multiple files can be specified using '+' as a delimiter.  All files
  247. should be unquoted names or quoted strings.  Any variables should be
  248. interpolated into double-quoted strings.
  249.  
  250.     [% INSERT legalese.txt + warning.txt %]
  251.     [% INSERT  "$legalese" + warning.txt %]  # requires quoting
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269. =item INCLUDE
  270.  
  271. The INCLUDE directive is used to process and include the output of
  272. another template file or block.
  273.  
  274.     [% INCLUDE header %]
  275.  
  276. If a BLOCK of the specified name is defined in the same file, or in a file 
  277. from which the current template has been called (i.e. a parent template) 
  278. then it will be used in preference to any file of the same name.
  279.  
  280.     [% INCLUDE table %]            # uses BLOCK defined below
  281.  
  282.     [% BLOCK table %]
  283.        <table>
  284.        ...
  285.        </table>
  286.     [% END %]
  287.  
  288. If a BLOCK definition is not currently visible then the template name
  289. should be a file relative to one of the INCLUDE_PATH directories, or
  290. an absolute or relative file name if the ABSOLUTE/RELATIVE options are
  291. appropriately enabled.  The INCLUDE directive automatically quotes the
  292. filename specified, as per INSERT described above.  When a variable
  293. contains the name of the template for the INCLUDE directive, it should
  294. be explicitly prefixed by '$' or double-quoted
  295.  
  296.     [% myheader = 'my/misc/header' %]
  297.     [% INCLUDE   myheader  %]            # 'myheader'
  298.     [% INCLUDE  $myheader  %]         # 'my/misc/header'
  299.     [% INCLUDE "$myheader" %]         # 'my/misc/header'
  300.  
  301. Any template directives embedded within the file will be processed
  302. accordingly.  All variables currently defined will be visible and 
  303. accessible from within the included template.  
  304.  
  305.     [% title = 'Hello World' %]
  306.     [% INCLUDE header %]
  307.     <body>
  308.     ...
  309.  
  310. 'header':
  311.  
  312.     <html>
  313.     <title>[% title %]</title>
  314.  
  315. output:
  316.  
  317.     <html>
  318.     <title>Hello World</title>
  319.     <body>
  320.     ...
  321.  
  322. Local variable definitions may be specified after the template name,
  323. temporarily masking any existing variables.  Insignificant whitespace
  324. is ignored within directives so you can add variable definitions on the
  325. same line, the next line or split across several line with comments
  326. interspersed, if you prefer.
  327.  
  328.     [% INCLUDE table %]
  329.  
  330.     [% INCLUDE table title="Active Projects" %]
  331.  
  332.     [% INCLUDE table 
  333.      title   = "Active Projects" 
  334.          bgcolor = "#80ff00"    # chartreuse
  335.      border  = 2
  336.     %]
  337.  
  338. The INCLUDE directive localises (i.e. copies) all variables before
  339. processing the template.  Any changes made within the included
  340. template will not affect variables in the including template.
  341.  
  342.     [% foo = 10 %]
  343.  
  344.     foo is originally [% foo %]
  345.     [% INCLUDE bar %]
  346.     foo is still [% foo %]
  347.  
  348.     [% BLOCK bar %]
  349.        foo was [% foo %]
  350.        [% foo = 20 %]
  351.        foo is now [% foo %]
  352.     [% END %]
  353.  
  354. output:
  355.     foo is originally 10
  356.        foo was 10
  357.        foo is now 20
  358.     foo is still 10
  359.  
  360. Technical Note: the localisation of the stash (that is, the process by
  361. which variables are copied before an INCLUDE to prevent being
  362. overwritten) is only skin deep.  The top-level variable namespace
  363. (hash) is copied, but no attempt is made to perform a deep-copy of
  364. other structures (hashes, arrays, objects, etc.)  Therefore, a 'foo'
  365. variable referencing a hash will be copied to create a new 'foo'
  366. variable but which points to the same hash array.  Thus, if you update
  367. compound variables (e.g. foo.bar) then you will change the original
  368. copy, regardless of any stash localisation.  If you're not worried
  369. about preserving variable values, or you trust the templates you're
  370. including then you might prefer to use the PROCESS directive which is
  371. faster by virtue of not performing any localisation.
  372.  
  373. From version 2.04 onwards, you can specify dotted variables as "local"
  374. variables to an INCLUDE directive.  However, be aware that because of
  375. the localisation issues explained above (if you skipped the previous
  376. Technical Note above then you might want to go back and read it or
  377. skip this section too), the variables might not actualy be "local".
  378. If the first element of the variable name already references a hash
  379. array then the variable update will affect the original variable.
  380.  
  381.     [% foo = {
  382.            bar = 'Baz'
  383.        }
  384.     %]
  385.   
  386.     [% INCLUDE somefile foo.bar='Boz' %]
  387.  
  388.     [% foo.bar %]        # Boz
  389.  
  390. This behaviour can be a little unpredictable (and may well be improved
  391. upon in a future version).  If you know what you're doing with it and 
  392. you're sure that the variables in question are defined (nor not) as you 
  393. expect them to be, then you can rely on this feature to implement some
  394. powerful "global" data sharing techniques.  Otherwise, you might prefer
  395. to steer well clear and always pass simple (undotted) variables as 
  396. parameters to INCLUDE and other similar directives.
  397.  
  398. If you want to process several templates in one go then you can 
  399. specify each of their names (quoted or unquoted names only, no unquoted
  400. '$variables') joined together by '+'.  The INCLUDE directive
  401. will then process them in order.
  402.  
  403.     [% INCLUDE html/header + "site/$header" + site/menu
  404.          title = "My Groovy Web Site"
  405.     %]
  406.  
  407. The variable stash is localised once and then the templates specified
  408. are processed in order, all within that same variable context.  This
  409. makes it slightly faster than specifying several separate INCLUDE
  410. directives (because you only clone the variable stash once instead of
  411. n times), but not quite as "safe" because any variable changes in the
  412. first file will be visible in the second, third and so on.  This
  413. might be what you want, of course, but then again, it might not.
  414.  
  415.  
  416.  
  417. =item PROCESS
  418.  
  419. The PROCESS directive is similar to INCLUDE but does not perform any 
  420. localisation of variables before processing the template.  Any changes
  421. made to variables within the included template will be visible in the
  422. including template.
  423.  
  424.     [% foo = 10 %]
  425.  
  426.     foo is [% foo %]
  427.     [% PROCESS bar %]
  428.     foo is [% foo %]
  429.  
  430.     [% BLOCK bar %]
  431.        [% foo = 20 %]
  432.        changed foo to [% foo %]
  433.     [% END %]
  434.  
  435. output:
  436.  
  437.     foo is 10
  438.        changed foo to 20
  439.     foo is 20
  440.  
  441. Parameters may be specified in the PROCESS directive, but these too will 
  442. become visible changes to current variable values.
  443.  
  444.     [% foo = 10 %]
  445.     foo is [% foo %]
  446.     [% PROCESS bar
  447.        foo = 20 
  448.     %]
  449.     foo is [% foo %]
  450.  
  451.     [% BLOCK bar %]
  452.        this is bar, foo is [% foo %]
  453.     [% END %]
  454.  
  455. output:
  456.  
  457.     foo is 10
  458.        this is bar, foo is 20
  459.     foo is 20
  460.  
  461. The PROCESS directive is slightly faster than INCLUDE because it
  462. avoids the need to localise (i.e. copy) the variable stash before
  463. processing the template.  As with INSERT and INCLUDE, the first
  464. parameter does not need to be quoted as long as it contains only
  465. alphanumeric characters, underscores, periods or forward slashes.
  466. A '$' prefix can be used to explicitly indicate a variable which 
  467. should be interpolated to provide the template name:
  468.  
  469.     [% myheader = 'my/misc/header' %]
  470.     [% PROCESS  myheader %]              # 'myheader'
  471.     [% PROCESS $myheader %]         # 'my/misc/header'
  472.  
  473. As with INCLUDE, multiple templates can be specified, delimited by
  474. '+', and are processed in order.
  475.  
  476.     [% PROCESS html/header + my/header %]
  477.  
  478.  
  479.  
  480.  
  481.  
  482. =item WRAPPER
  483.  
  484. It's not unusual to find yourself adding common headers and footers to 
  485. pages or sub-sections within a page.  Something like this:
  486.  
  487.     [% INCLUDE section/header
  488.        title = 'Quantum Mechanics'
  489.     %]
  490.        Quantum mechanics is a very interesting subject wish 
  491.        should prove easy for the layman to fully comprehend.
  492.     [% INCLUDE section/footer %]
  493.  
  494.     [% INCLUDE section/header
  495.        title = 'Desktop Nuclear Fusion for under $50'
  496.     %]
  497.        This describes a simple device which generates significant 
  498.        sustainable electrical power from common tap water by process 
  499.        of nuclear fusion.
  500.     [% INCLUDE section/footer %]
  501.  
  502. The individual template components being included might look like these:
  503.  
  504. section/header:
  505.  
  506.     <p>
  507.     <h2>[% title %]</h2>
  508.  
  509. section/footer:
  510.  
  511.     </p>
  512.  
  513. The WRAPPER directive provides a way of simplifying this a little.  It
  514. encloses a block up to a matching END directive, which is first
  515. processed to generate some output.  This is then passed to the named
  516. template file or BLOCK as the 'content' variable.
  517.  
  518.     [% WRAPPER section
  519.        title = 'Quantum Mechanics'
  520.     %]
  521.        Quantum mechanics is a very interesting subject wish 
  522.        should prove easy for the layman to fully comprehend.
  523.     [% END %]
  524.  
  525.     [% WRAPPER section
  526.        title = 'Desktop Nuclear Fusion for under $50'
  527.     %]
  528.        This describes a simple device which generates significant 
  529.        sustainable electrical power from common tap water by process 
  530.        of nuclear fusion.
  531.     [% END %]
  532.  
  533. The single 'section' template can then be defined as:
  534.  
  535.     <p>
  536.     <h2>[% title %]</h2>
  537.     [% content %]
  538.     </p>
  539.  
  540. Like other block directives, it can be used in side-effect notation:
  541.  
  542.     [% INSERT legalese.txt WRAPPER big_bold_table %]
  543.  
  544. It's also possible to specify multiple templates to a WRAPPER directive.
  545. The specification order indicates outermost to innermost wrapper templates.
  546. For example, given the following template block definitions:
  547.  
  548.     [% BLOCK bold   %]<b>[% content %]</b>[% END %]
  549.     [% BLOCK italic %]<i>[% content %]</i>[% END %]
  550.  
  551. the directive 
  552.  
  553.     [% WRAPPER bold+italic %]Hello World[% END %]
  554.  
  555. would generate the following output:
  556.  
  557.     <b><i>Hello World</i></b>
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576. =item BLOCK
  577.  
  578. The BLOCK ... END construct can be used to define template component
  579. blocks which can be processed with the INCLUDE, PROCESS and WRAPPER
  580. directives.
  581.  
  582.     [% BLOCK tabrow %]
  583.     <tr><td>[% name %]<td><td>[% email %]</td></tr>
  584.     [% END %]
  585.  
  586.     <table>
  587.     [% PROCESS tabrow  name='Fred'  email='fred@nowhere.com' %]
  588.     [% PROCESS tabrow  name='Alan'  email='alan@nowhere.com' %]
  589.     </table>
  590.  
  591. A BLOCK definition can be used before it is defined, as long as the
  592. definition resides in the same file.  The block definition itself does
  593. not generate any output.
  594.  
  595.     [% PROCESS tmpblk %]
  596.  
  597.     [% BLOCK tmpblk %] This is OK [% END %]
  598.  
  599. You can use an anonymous BLOCK to capture the output of a template
  600. fragment.  
  601.  
  602.     [% julius = BLOCK %]
  603.        And Caesar's spirit, ranging for revenge,
  604.        With Ate by his side come hot from hell,
  605.        Shall in these confines with a monarch's voice
  606.        Cry  'Havoc', and let slip the dogs of war;
  607.        That this foul deed shall smell above the earth
  608.        With carrion men, groaning for burial.
  609.     [% END %]
  610.  
  611. Like a named block, it can contain any other template directives which 
  612. are processed when the block is defined.  The output generated by the 
  613. block is then assigned to the variable 'julius'.
  614.  
  615. Anonymous BLOCKs can also be used to define block macros.  The
  616. enclosing block is processed each time the macro is called.
  617.  
  618.     [% MACRO locate BLOCK %]
  619.        The [% animal %] sat on the [% place %].
  620.     [% END %]
  621.  
  622.     [% locate(animal='cat', place='mat') %]    # The cat sat on the mat
  623.     [% locate(animal='dog', place='log') %]    # The dog sat on the log
  624.  
  625.  
  626.  
  627. =back
  628.  
  629. =head2 Conditional Processing
  630.  
  631. =over 4
  632.  
  633.  
  634. =item IF / UNLESS / ELSIF / ELSE
  635.  
  636. The IF and UNLESS directives can be used to process or ignore a
  637. block based on some run-time condition.  
  638.  
  639.     [% IF frames %]
  640.        [% INCLUDE frameset %]
  641.     [% END %]
  642.  
  643.     [% UNLESS text_mode %]
  644.        [% INCLUDE biglogo %]
  645.     [% END %]
  646.  
  647. Multiple conditions may be joined with ELSIF and/or ELSE blocks.
  648.  
  649.     [% IF age < 10 %]
  650.        Hello [% name %], does your mother know you're 
  651.        using her AOL account?
  652.     [% ELSIF age < 18 %]
  653.        Sorry, you're not old enough to enter 
  654.        (and too dumb to lie about your age)
  655.     [% ELSE %]
  656.        Welcome [% name %].
  657.     [% END %]
  658.  
  659. The following conditional and boolean operators may be used:
  660.  
  661.     == != < <= > >= && || ! and or not
  662.  
  663. Note that C<and>, C<or> and C<not> are also provided as aliases for
  664. C<&&>, C<||> and C<!>, respectively.
  665.  
  666. Conditions may be arbitrarily complex and are evaluated with the same
  667. precedence as in Perl.  Parenthesis may be used to explicitly
  668. determine evaluation order.
  669.  
  670.     # ridiculously contrived complex example
  671.     [% IF (name == 'admin' || uid <= 0) && mode == 'debug' %]
  672.        I'm confused.
  673.     [% ELSIF more > less %]
  674.        That's more or less correct.
  675.     [% END %]
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682. =item SWITCH / CASE
  683.  
  684. The SWITCH / CASE construct can be used to perform a multi-way
  685. conditional test.  The SWITCH directive expects an expression which is
  686. first evaluated and then compared against each CASE statement in turn.
  687. Each CASE directive should contain a single value or a list of values
  688. which should match.  CASE may also be left blank or written as [% CASE
  689. DEFAULT %] to specify a default match.  Only one CASE matches, there
  690. is no drop-through between CASE statements.
  691.  
  692.     [% SWITCH myvar %]
  693.     [% CASE value1 %]
  694.        ...
  695.     [% CASE [ value2 value3 ] %]   # multiple values
  696.        ...
  697.     [% CASE myhash.keys %]         # ditto
  698.        ...
  699.     [% CASE %]                     # default
  700.        ...
  701.     [% END %]
  702.   
  703.  
  704.  
  705.  
  706. =back
  707.  
  708. =head2 Loop Processing
  709.  
  710. =over 4
  711.  
  712.  
  713. =item FOREACH
  714.  
  715. The FOREACH directive will iterate through the items in a list, processing
  716. the enclosed block for each one.
  717.  
  718.     my $vars = {
  719.     foo   => 'Foo',
  720.       items => [ 'one', 'two', 'three' ],
  721.     };
  722.   
  723. template:
  724.  
  725.     Things:
  726.     [% FOREACH thing = [ foo 'Bar' "$foo Baz" ] %]
  727.        * [% thing %]
  728.     [% END %]
  729.   
  730.     Items:
  731.     [% FOREACH i = items %]
  732.        * [% i %]
  733.     [% END %]
  734.   
  735.     Stuff:
  736.     [% stuff = [ foo "$foo Bar" ] %]
  737.     [% FOREACH s = stuff %]
  738.        * [% s %]
  739.     [% END %]
  740.  
  741. output:
  742.  
  743.     Things:
  744.       * Foo
  745.       * Bar
  746.       * Foo Baz
  747.   
  748.     Items:
  749.       * one
  750.       * two
  751.       * three
  752.   
  753.     Stuff:
  754.       * Foo
  755.       * Foo Bar
  756.  
  757. You can use also use 'IN' instead of '=' if you prefer.
  758.  
  759.     [% FOREACH crook IN government %]
  760.     
  761. When the FOREACH directive is used without specifying a target variable, 
  762. any iterated values which are hash references will be automatically 
  763. imported.
  764.  
  765.     [% userlist = [
  766.       { id => 'tom',   name => 'Thomas'  },
  767.       { id => 'dick',  name => 'Richard'  },
  768.       { id => 'larry', name => 'Lawrence' },
  769.        ]
  770.     %]
  771.  
  772.     [% FOREACH user IN userlist %]
  773.        [% user.id %] [% user.name %]
  774.     [% END %]
  775.  
  776. short form:
  777.  
  778.     [% FOREACH userlist %]
  779.        [% id %] [% name %]
  780.     [% END %]
  781.  
  782. Note that this particular usage creates a localised variable context
  783. to prevent the imported hash keys from overwriting any existing
  784. variables.  The imported definitions and any other variables defined
  785. in such a FOREACH loop will be lost at the end of the loop, when the 
  786. previous context and variable values are restored.
  787.  
  788. However, under normal operation, the loop variable remains in scope
  789. after the FOREACH loop has ended (caveat: overwriting any variable
  790. previously in scope). This is useful as the loop variable is secretly
  791. an iterator object (see below) and can be used to analyse the last
  792. entry processed by the loop.
  793.  
  794. The FOREACH directive can also be used to iterate through the entries
  795. in a hash array.  Each entry in the hash is returned in sorted order
  796. (based on the key) as a hash array containing 'key' and 'value' items.
  797.  
  798.     [% users = {
  799.      tom   => 'Thomas',
  800.      dick  => 'Richard',
  801.          larry => 'Lawrence',
  802.        }
  803.     %]
  804.  
  805.     [% FOREACH u IN users %]
  806.        * [% u.key %] : [% u.value %]
  807.     [% END %]
  808.  
  809. Output:
  810.  
  811.        * dick : Richard
  812.        * larry : Lawrence
  813.        * tom : Thomas      
  814.  
  815. The NEXT directive starts the next iteration in the FOREACH loop.
  816.  
  817.     [% FOREACH user IN userlist %]
  818.        [% NEXT IF user.isguest %]
  819.        Name: [% user.name %]    Email: [% user.email %]
  820.     [% END %]
  821.  
  822. The LAST directive can be used to prematurely exit the loop.  BREAK is
  823. also provided as an alias for LAST.
  824.  
  825.     [% FOREACH match IN results.nsort('score').reverse %]
  826.        [% LAST IF match.score < 50 %]
  827.        [% match.score %] : [% match.url %]
  828.     [% END %]
  829.  
  830. The FOREACH directive is implemented using the Template::Iterator
  831. module.  A reference to the iterator object for a FOREACH directive is
  832. implicitly available in the 'loop' variable.  The following methods 
  833. can be called on the 'loop' iterator.
  834.  
  835.     size()    number of elements in the list
  836.     max()       index number of last element (size - 1)
  837.     index()     index of current iteration from 0 to max()
  838.     count()     iteration counter from 1 to size() (i.e. index() + 1)
  839.     first()     true if the current iteration is the first
  840.     last()      true if the current iteration is the last
  841.     prev()      return the previous item in the list
  842.     next()      return the next item in the list
  843.  
  844. See L<Template::Iterator> for further details.
  845.  
  846. Example:
  847.  
  848.     [% FOREACH item IN [ 'foo', 'bar', 'baz' ] -%]
  849.        [%- "<ul>\n" IF loop.first %]
  850.        <li>[% loop.count %]/[% loop.size %]: [% item %]
  851.        [%- "</ul>\n" IF loop.last %]
  852.     [% END %]
  853.  
  854. Output:
  855.  
  856.     <ul>
  857.     <li>1/3: foo
  858.     <li>2/3: bar
  859.     <li>3/3: baz
  860.     </ul>
  861.  
  862. Note that the number() method is supported as an alias for count() for
  863. backwards compatibility but may be deprecated in some future version.
  864.  
  865. Nested loops will work as expected, with the 'loop' variable correctly 
  866. referencing the innermost loop and being restored to any previous 
  867. value (i.e. an outer loop) at the end of the loop.
  868.  
  869.     [% FOREACH group IN grouplist;
  870.        # loop => group iterator
  871.            "Groups:\n" IF loop.first;
  872.  
  873.            FOREACH user IN group.userlist;
  874.                # loop => user iterator
  875.            "$loop.count: $user.name\n";
  876.        END;
  877.  
  878.        # loop => group iterator
  879.            "End of Groups\n" IF loop.last;
  880.        END 
  881.     %]
  882.  
  883. The 'iterator' plugin can also be used to explicitly create an
  884. iterator object.  This can be useful within nested loops where you
  885. need to keep a reference to the outer iterator within the inner loop.
  886. The iterator plugin effectively allows you to create an iterator by a
  887. name other than 'loop'.  See Template::Plugin::Iterator for further
  888. details.
  889.  
  890.     [% USE giter = iterator(grouplist) %]
  891.  
  892.     [% FOREACH group IN giter %]
  893.        [% FOREACH user IN group.userlist %]
  894.              user #[% loop.count %] in
  895.              group [% giter.count %] is
  896.              named [% user.name %]
  897.        [% END %]
  898.     [% END %]
  899.  
  900.  
  901.  
  902.  
  903. =item WHILE
  904.  
  905. The WHILE directive can be used to repeatedly process a template block
  906. while a conditional expression evaluates true.  The expression may 
  907. be arbitrarily complex as per IF / UNLESS.
  908.  
  909.     [% WHILE total < 100 %]
  910.        ...
  911.        [% total = calculate_new_total %]
  912.     [% END %]
  913.  
  914. An assignment can be enclosed in parenthesis to evaluate the assigned
  915. value.
  916.  
  917.     [% WHILE (user = get_next_user_record) %]
  918.        [% user.name %]
  919.     [% END %]
  920.  
  921. The NEXT directive can be used to start the next iteration of a 
  922. WHILE loop and BREAK can be used to exit the loop, both as per FOREACH.
  923.  
  924. The Template Toolkit uses a failsafe counter to prevent runaway WHILE
  925. loops which would otherwise never terminate.  If the loop exceeds 1000
  926. iterations then an 'undef' exception will be thrown, reporting the
  927. error:
  928.  
  929.     WHILE loop terminated (> 1000 iterations)
  930.  
  931. The $Template::Directive::WHILE_MAX variable controls this behaviour
  932. and can be set to a higher value if necessary.
  933.  
  934.  
  935. =back
  936.  
  937. =head2 Filters, Plugins, Macros and Perl
  938.  
  939. =over 4
  940.  
  941.  
  942. =item FILTER
  943.  
  944. The FILTER directive can be used to post-process the output of a
  945. block.  A number of standard filters are provided with the Template
  946. Toolkit.  The 'html' filter, for example, escapes the 'E<lt>', 'E<gt>'
  947. and '&' characters to prevent them from being interpreted as HTML tags
  948. or entity reference markers.
  949.  
  950.     [% FILTER html %]
  951.        HTML text may have < and > characters embedded
  952.        which you want converted to the correct HTML entities.
  953.     [% END %]
  954.  
  955. output:
  956.  
  957.        HTML text may have < and > characters embedded
  958.        which you want converted to the correct HTML entities.
  959.  
  960. The FILTER directive can also follow various other non-block directives.
  961. For example:
  962.  
  963.     [% INCLUDE mytext FILTER html %]
  964.  
  965. The '|' character can also be used as an alias for 'FILTER'.
  966.  
  967.     [% INCLUDE mytext | html %]
  968.  
  969. Multiple filters can be chained together and will be called in sequence.
  970.  
  971.     [% INCLUDE mytext FILTER html FILTER html_para %]
  972.  
  973. or
  974.  
  975.     [% INCLUDE mytext | html | html_para %]
  976.  
  977. Filters come in two flavours, known as 'static' or 'dynamic'.  A
  978. static filter is a simple subroutine which accepts a text string as
  979. the only argument and returns the modified text.  The 'html' filter is
  980. an example of a static filter, implemented as:
  981.  
  982.     sub html_filter {
  983.     my $text = shift;
  984.         for ($text) {
  985.         s/&/&/g;
  986.         s/</</g;
  987.         s/>/>/g;
  988.         }
  989.     return $text;
  990.     }
  991.  
  992. Dynamic filters can accept arguments which are specified when the filter
  993. is called from a template.  The 'repeat' filter is such an example, 
  994. accepting a numerical argument which specifies the number of times
  995. that the input text should be repeated.
  996.  
  997.     [% FILTER repeat(3) %]blah [% END %]
  998.  
  999. output:
  1000.  
  1001.     blah blah blah
  1002.  
  1003. These are implemented as filter 'factories'.  The factory subroutine
  1004. is passed a reference to the current Template::Context object along
  1005. with any additional arguments specified.  It should then return a
  1006. subroutine reference (e.g. a closure) which implements the filter.
  1007. The 'repeat' filter factory is implemented like this:
  1008.  
  1009.     sub repeat_filter_factory {
  1010.     my ($context, $iter) = @_;
  1011.     $iter = 1 unless defined $iter;
  1012.  
  1013.     return sub {
  1014.         my $text = shift;
  1015.         $text = '' unless defined $text;
  1016.         return join('\n', $text) x $iter;
  1017.     }
  1018.     }
  1019.  
  1020. The FILTERS option, described in L<Template::Manual::Config>, allows 
  1021. custom filters to be defined when a Template object is instantiated.  
  1022. The Template::Context define_filter() method allows further filters
  1023. to be defined at any time.
  1024.  
  1025. When using a filter, it is possible to assign an alias to it for 
  1026. further use.  This is most useful for dynamic filters that you want 
  1027. to re-use with the same configuration.
  1028.  
  1029.     [% FILTER echo = repeat(2) %]
  1030.     Is there anybody out there?
  1031.     [% END %]
  1032.  
  1033.     [% FILTER echo %]
  1034.     Mother, should I build a wall?
  1035.     [% END %]
  1036.  
  1037. Output:
  1038.  
  1039.     Is there anybody out there?
  1040.     Is there anybody out there?
  1041.  
  1042.     Mother, should I build a wall?
  1043.     Mother, should I build a wall?
  1044.  
  1045. The FILTER directive automatically quotes the name of the filter.  As
  1046. with INCLUDE et al, you can use a variable to provide the name of the 
  1047. filter, prefixed by '$'.
  1048.  
  1049.     [% myfilter = 'html' %]
  1050.     [% FILTER $myfilter %]    # same as [% FILTER html %]
  1051.        ...
  1052.     [% END %]
  1053.  
  1054. A template variable can also be used to define a static filter
  1055. subroutine.  However, the Template Toolkit will automatically call any
  1056. subroutine bound to a variable and use the value returned.  Thus, the
  1057. above example could be implemented as:
  1058.  
  1059.     my $vars = {
  1060.     myfilter => sub { return 'html' },
  1061.     };
  1062.  
  1063. template:
  1064.  
  1065.     [% FILTER $myfilter %]    # same as [% FILTER html %]
  1066.        ...
  1067.     [% END %]
  1068.  
  1069. To define a template variable that evaluates to a subroutine reference
  1070. that can be used by the FILTER directive, you should create a
  1071. subroutine that, when called automatically by the Template Toolkit,
  1072. returns another subroutine reference which can then be used to perform
  1073. the filter operation.  Note that only static filters can be
  1074. implemented in this way.
  1075.  
  1076.     my $vars = {
  1077.     myfilter => sub { \&my_filter_sub },
  1078.     };
  1079.  
  1080.     sub my_filter_sub {
  1081.     my $text = shift;
  1082.     # do something
  1083.         return $text;
  1084.     }
  1085.  
  1086. template:
  1087.  
  1088.     [% FILTER $myfilter %]
  1089.        ...
  1090.     [% END %]
  1091.  
  1092. Alternately, you can bless a subroutine reference into a class (any
  1093. class will do) to fool the Template Toolkit into thinking it's an
  1094. object rather than a subroutine.  This will then bypass the automatic
  1095. "call-a-subroutine-to-return-a-value" magic.
  1096.  
  1097.     my $vars = {
  1098.     myfilter => bless(\&my_filter_sub, 'anything_you_like'),
  1099.     };
  1100.  
  1101. template:
  1102.  
  1103.     [% FILTER $myfilter %]        
  1104.        ...
  1105.     [% END %]
  1106.  
  1107. Filters bound to template variables remain local to the variable
  1108. context in which they are defined.  That is, if you define a filter in
  1109. a PERL block within a template that is loaded via INCLUDE, then the
  1110. filter definition will only exist until the end of that template when
  1111. the stash is delocalised, restoring the previous variable state.  If
  1112. you want to define a filter which persists for the lifetime of the
  1113. processor, or define additional dynamic filter factories, then you can
  1114. call the define_filter() method on the current Template::Context
  1115. object.
  1116.  
  1117. See L<Template::Manual::Filters> for a complete list of available filters,
  1118. their descriptions and examples of use.
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125. =item USE
  1126.  
  1127. The USE directive can be used to load and initialise "plugin"
  1128. extension modules.
  1129.  
  1130.     [% USE myplugin %]
  1131.  
  1132. A plugin is a regular Perl module that conforms to a particular
  1133. object-oriented interface, allowing it to be loaded into and used
  1134. automatically by the Template Toolkit.  For details of this interface
  1135. and information on writing plugins, consult L<Template::Plugin>. 
  1136.  
  1137. The plugin name is case-sensitive and will be appended to the
  1138. PLUGIN_BASE value (default: 'Template::Plugin') to construct a full
  1139. module name.  Any periods, '.', in the name will be converted to '::'.
  1140.  
  1141.     [% USE MyPlugin %]     #  => Template::Plugin::MyPlugin
  1142.     [% USE Foo.Bar  %]     #  => Template::Plugin::Foo::Bar
  1143.  
  1144. Various standard plugins are included with the Template Toolkit (see 
  1145. below and L<Template::Manual::Plugins>).  These can be specified in lower
  1146. case and are mapped to the appropriate name.
  1147.  
  1148.     [% USE cgi   %]        # => Template::Plugin::CGI
  1149.     [% USE table %]        # => Template::Plugin::Table
  1150.  
  1151. Any additional parameters supplied in parenthesis after the plugin
  1152. name will be also be passed to the new() constructor.  A reference to
  1153. the current Template::Context object is always passed as the first
  1154. parameter.
  1155.  
  1156.     [% USE MyPlugin('foo', 123) %]
  1157.  
  1158. equivalent to:
  1159.  
  1160.     Template::Plugin::MyPlugin->new($context, 'foo', 123);
  1161.  
  1162. Named parameters may also be specified.  These are collated into a
  1163. hash which is passed by reference as the last parameter to the
  1164. constructor, as per the general code calling interface.
  1165.  
  1166.     [% USE url('/cgi-bin/foo', mode='submit', debug=1) %]
  1167.  
  1168. equivalent to:
  1169.  
  1170.     Template::Plugin::URL->new($context, '/cgi-bin/foo'
  1171.                    { mode => 'submit', debug => 1 });
  1172.  
  1173. The plugin may represent any data type; a simple variable, hash, list or
  1174. code reference, but in the general case it will be an object reference.
  1175. Methods can be called on the object (or the relevant members of the
  1176. specific data type) in the usual way:
  1177.  
  1178.     [% USE table(mydata, rows=3) %]
  1179.  
  1180.     [% FOREACH row = table.rows %]
  1181.        <tr>    
  1182.        [% FOREACH item = row %]
  1183.       <td>[% item %]</td>
  1184.        [% END %]
  1185.        </tr>
  1186.     [% END %]
  1187.  
  1188. An alternative name may be provided for the plugin by which it can be 
  1189. referenced:
  1190.  
  1191.     [% USE scores = table(myscores, cols=5) %]
  1192.  
  1193.     [% FOREACH row = scores.rows %]
  1194.        ...
  1195.     [% END %]
  1196.  
  1197. You can use this approach to create multiple plugin objects with
  1198. different configurations.  This example shows how the 'format' plugin
  1199. is used to create sub-routines bound to variables for formatting text
  1200. as per printf().
  1201.  
  1202.     [% USE bold = format('<b>%s</b>') %]
  1203.     [% USE ital = format('<i>%s</i>') %]
  1204.  
  1205.     [% bold('This is bold')   %]
  1206.     [% ital('This is italic') %]
  1207.  
  1208. Output:
  1209.  
  1210.     <b>This is bold</b>
  1211.     <i>This is italic</i>
  1212.  
  1213. This next example shows how the URL plugin can be used to build
  1214. dynamic URLs from a base part and optional query parameters.
  1215.  
  1216.     [% USE mycgi = URL('/cgi-bin/foo.pl', debug=1) %]
  1217.     <a href="[% mycgi %]">...
  1218.     <a href="[% mycgi(mode='submit') %]"...
  1219.  
  1220. Output:
  1221.  
  1222.     <a href="/cgi-bin/foo.pl?debug=1">...
  1223.     <a href="/cgi-bin/foo.pl?mode=submit&debug=1">...
  1224.  
  1225. The CGI plugin is an example of one which delegates to another Perl
  1226. module.  In this this case, it is to Lincoln Stein's CGI.pm module.
  1227. All of the methods provided by CGI.pm are available via the plugin.
  1228.  
  1229.     [% USE CGI %]
  1230.  
  1231.     [% CGI.start_form %]
  1232.  
  1233.     [% CGI.checkbox_group(name   =>   'colours', 
  1234.                           values => [ 'red' 'green' 'blue' ])
  1235.     %]
  1236.  
  1237.     [% CGI.popup_menu(name   =>   'items', 
  1238.                       values => [ 'foo' 'bar' 'baz' ])
  1239.     %]
  1240.  
  1241.     [% CGI.end_form %]
  1242.  
  1243. Simon Matthews has written the DBI plugin which provides an interface
  1244. to Tim Bunce's DBI module (available from CPAN).  Here's a short
  1245. example:
  1246.  
  1247.     [% USE DBI('DBI:mSQL:mydbname') %]
  1248.  
  1249.     [% FOREACH user = DBI.query('SELECT * FROM users') %]
  1250.        [% user.id %] [% user.name %] [% user.etc.etc %]
  1251.     [% END %]
  1252.  
  1253. See L<Template::Manual::Plugins> for more information on the plugins
  1254. distributed with the toolkit or available from CPAN.
  1255.  
  1256. The LOAD_PERL option (disabled by default) provides a further way by
  1257. which external Perl modules may be loaded.  If a regular Perl module
  1258. (i.e. not a Template::Plugin::* or other module relative to some
  1259. PLUGIN_BASE) supports an object-oriented interface and a new()
  1260. constructor then it can be loaded and instantiated automatically.  The
  1261. following trivial example shows how the IO::File module might be used.
  1262.  
  1263.     [% USE file = IO.File('/tmp/mydata') %]
  1264.  
  1265.     [% WHILE (line = file.getline) %]
  1266.        <!-- [% line %] -->
  1267.     [% END %]
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274. =item MACRO
  1275.  
  1276. The MACRO directive allows you to define a directive or directive block
  1277. which is then evaluated each time the macro is called. 
  1278.  
  1279.     [% MACRO header INCLUDE header %]
  1280.  
  1281. Calling the macro as:
  1282.  
  1283.     [% header %]
  1284.  
  1285. is then equivalent to:
  1286.  
  1287.     [% INCLUDE header %]
  1288.  
  1289. Macros can be passed named parameters when called.  These values remain 
  1290. local to the macro.
  1291.  
  1292.     [% header(title='Hello World') %]  
  1293.  
  1294. equivalent to:
  1295.  
  1296.     [% INCLUDE header title='Hello World' %]
  1297.  
  1298. A MACRO definition may include parameter names.  Values passed to the 
  1299. macros are then mapped to these local variables.  Other named parameters
  1300. may follow these.
  1301.  
  1302.     [% MACRO header(title) INCLUDE header %]
  1303.  
  1304.     [% header('Hello World') %]
  1305.     [% header('Hello World', bgcol='#123456') %]
  1306.  
  1307. equivalent to:
  1308.  
  1309.     [% INCLUDE header title='Hello World' %]
  1310.     [% INCLUDE header title='Hello World' bgcol='#123456' %]
  1311.  
  1312. Here's another example, defining a macro for display numbers
  1313. in comma-delimited groups of 3, using the chunk and join virtual
  1314. method.
  1315.  
  1316.     [% MACRO number(n) GET n.chunk(-3).join(',') %]
  1317.  
  1318.     [% number(1234567) %]    # 1,234,567
  1319.  
  1320. A MACRO may precede any directive and must conform to the structure 
  1321. of the directive.
  1322.  
  1323.     [% MACRO header IF frames %]
  1324.        [% INCLUDE frames/header %]
  1325.     [% ELSE %]
  1326.        [% INCLUDE header %]
  1327.     [% END %]
  1328.  
  1329.     [% header %]
  1330.  
  1331. A MACRO may also be defined as an anonymous BLOCK.  The block will be
  1332. evaluated each time the macro is called. 
  1333.  
  1334.     [% MACRO header BLOCK %]
  1335.        ...content...
  1336.     [% END %]
  1337.  
  1338.     [% header %]
  1339.  
  1340. If you've got the EVAL_PERL option set, then you can even define a
  1341. MACRO as a PERL block (see below):
  1342.  
  1343.     [% MACRO triple(n) PERL %]
  1344.          my $n = $stash->get('n');
  1345.          print $n * 3;
  1346.     [% END -%]
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354. =item PERL
  1355.  
  1356. (for the advanced reader)
  1357.  
  1358. The PERL directive is used to mark the start of a block which contains
  1359. Perl code for evaluation.  The EVAL_PERL option must be enabled for Perl
  1360. code to be evaluated or a 'perl' exception will be thrown with the 
  1361. message 'EVAL_PERL not set'.
  1362.  
  1363. Perl code is evaluated in the Template::Perl package.  The $context
  1364. package variable contains a reference to the current Template::Context
  1365. object.  This can be used to access the functionality of the Template
  1366. Toolkit to process other templates, load plugins, filters, etc.
  1367. See L<Template::Context> for further details.
  1368.  
  1369.     [% PERL %]
  1370.        print $context->include('myfile');
  1371.     [% END %]
  1372.  
  1373. The $stash variable contains a reference to the top-level stash object
  1374. which manages template variables.  Through this, variable values can
  1375. be retrieved and updated.  See L<Template::Stash> for further details.
  1376.  
  1377.     [% PERL %]
  1378.        $stash->set(foo => 'bar');
  1379.        print "foo value: ", $stash->get('foo');
  1380.     [% END %]
  1381.  
  1382. Output
  1383.     foo value: bar
  1384.  
  1385. Output is generated from the PERL block by calling print().  Note that
  1386. the Template::Perl::PERLOUT handle is selected (tied to an output
  1387. buffer) instead of STDOUT.
  1388.  
  1389.     [% PERL %]
  1390.        print "foo\n";                            # OK
  1391.        print PERLOUT "bar\n";                   # OK, same as above
  1392.        print Template::Perl::PERLOUT "baz\n";   # OK, same as above
  1393.        print STDOUT "qux\n";            # WRONG!
  1394.     [% END %]
  1395.  
  1396. The PERL block may contain other template directives.  These are
  1397. processed before the Perl code is evaluated.
  1398.  
  1399.     [% name = 'Fred Smith' %]
  1400.  
  1401.     [% PERL %]
  1402.        print "[% name %]\n";
  1403.     [% END %]
  1404.  
  1405. Thus, the Perl code in the above example is evaluated as:
  1406.  
  1407.     print "Fred Smith\n";
  1408.  
  1409. Exceptions may be thrown from within PERL blocks via die() and will be
  1410. correctly caught by enclosing TRY blocks.
  1411.  
  1412.     [% TRY %]
  1413.        [% PERL %]
  1414.           die "nothing to live for\n";
  1415.        [% END %]
  1416.     [% CATCH %]
  1417.        error: [% error.info %]
  1418.     [% END %]
  1419.  
  1420. output:
  1421.        error: nothing to live for
  1422.  
  1423.  
  1424.  
  1425.  
  1426. =item RAWPERL
  1427.  
  1428. (for the very advanced reader)
  1429.  
  1430. The Template Toolkit parser reads a source template and generates the
  1431. text of a Perl subroutine as output.  It then uses eval() to evaluate
  1432. it into a subroutine reference.  This subroutine is then called to
  1433. process the template, passing a reference to the current
  1434. Template::Context object through which the functionality of the
  1435. Template Toolkit can be accessed.  The subroutine reference can be
  1436. cached, allowing the template to be processed repeatedly without
  1437. requiring any further parsing.
  1438.  
  1439. For example, a template such as:
  1440.  
  1441.     [% PROCESS header %]
  1442.     The [% animal %] sat on the [% location %]
  1443.     [% PROCESS footer %]
  1444.  
  1445. is converted into the following Perl subroutine definition:
  1446.  
  1447.     sub {
  1448.         my $context = shift;
  1449.         my $stash   = $context->stash;
  1450.         my $output  = '';
  1451.         my $error;
  1452.         
  1453.         eval { BLOCK: {
  1454.             $output .=  $context->process('header');
  1455.             $output .=  "The ";
  1456.             $output .=  $stash->get('animal');
  1457.             $output .=  " sat on the ";
  1458.             $output .=  $stash->get('location');
  1459.             $output .=  $context->process('footer');
  1460.             $output .=  "\n";
  1461.         } };
  1462.         if ($@) {
  1463.             $error = $context->catch($@, \$output);
  1464.             die $error unless $error->type eq 'return';
  1465.         }
  1466.     
  1467.         return $output;
  1468.     }
  1469.  
  1470. To examine the Perl code generated, such as in the above example, set
  1471. the $Template::Parser::DEBUG package variable to any true value.  You
  1472. can also set the $Template::Directive::PRETTY variable true to have
  1473. the code formatted in a readable manner for human consumption.  The
  1474. source code for each generated template subroutine will be printed to
  1475. STDERR on compilation (i.e. the first time a template is used).
  1476.  
  1477.     $Template::Parser::DEBUG = 1;
  1478.     $Template::Directive::PRETTY = 1;
  1479.  
  1480.     ...
  1481.  
  1482.     $template->process($file, $vars)
  1483.     || die $template->error(), "\n";
  1484.  
  1485. The PERL ... END construct allows Perl code to be embedded into a
  1486. template (when the EVAL_PERL option is set), but it is evaluated at
  1487. "runtime" using eval() each time the template subroutine is called.
  1488. This is inherently flexible, but not as efficient as it could be,
  1489. especially in a persistent server environment where a template may be
  1490. processed many times.  
  1491.  
  1492. The RAWPERL directive allows you to write Perl code that is integrated
  1493. directly into the generated Perl subroutine text.  It is evaluated
  1494. once at compile time and is stored in cached form as part of the
  1495. compiled template subroutine.  This makes RAWPERL blocks more
  1496. efficient than PERL blocks.
  1497.  
  1498. The downside is that you must code much closer to the metal.  Within
  1499. PERL blocks, you can call print() to generate some output.  RAWPERL
  1500. blocks don't afford such luxury.  The code is inserted directly into
  1501. the generated subroutine text and should conform to the convention of
  1502. appending to the '$output' variable.
  1503.  
  1504.     [% PROCESS  header %]
  1505.  
  1506.     [% RAWPERL %]
  1507.        $output .= "Some output\n";
  1508.        ...
  1509.        $output .= "Some more output\n";
  1510.     [% END %]
  1511.  
  1512. The critical section of the generated subroutine for this example would 
  1513. then look something like:
  1514.  
  1515.     ...
  1516.     eval { BLOCK: {
  1517.     $output .=  $context->process('header');
  1518.         $output .=  "\n";
  1519.         $output .= "Some output\n";
  1520.     ...
  1521.         $output .= "Some more output\n";
  1522.         $output .=  "\n";
  1523.     } };
  1524.     ...
  1525.  
  1526. As with PERL blocks, the $context and $stash references are pre-defined
  1527. and available for use within RAWPERL code. 
  1528.  
  1529.  
  1530. =back 
  1531.  
  1532. =head2 Exception Handling and Flow Control
  1533.  
  1534. =over 4
  1535.  
  1536.  
  1537. =item TRY / THROW / CATCH / FINAL
  1538.  
  1539. (more advanced material)
  1540.  
  1541. The Template Toolkit supports fully functional, nested exception
  1542. handling.  The TRY directive introduces an exception handling scope 
  1543. which continues until the matching END directive.  Any errors that 
  1544. occur within that block will be caught and can be handled by one
  1545. of the CATCH blocks defined.
  1546.  
  1547.     [% TRY %]
  1548.        ...blah...blah...
  1549.        [% CALL somecode %]
  1550.        ...etc...
  1551.        [% INCLUDE someblock %]
  1552.        ...and so on...
  1553.     [% CATCH %]
  1554.        An error occurred!
  1555.     [% END %]
  1556.  
  1557. Errors are raised as exceptions (objects of the Template::Exception 
  1558. class) and contain two fields, 'type' and 'info'.  The exception 
  1559. 'type' can be any string containing letters, numbers, '_' or '.', and
  1560. is used to indicate the kind of error that occurred.  The 'info' field
  1561. contains an error message indicating what actually went wrong.  Within
  1562. a catch block, the exception object is aliased to the 'error' variable.
  1563. You can access the 'type' and 'info' fields directly.
  1564.  
  1565.     [% mydsn = 'dbi:MySQL:foobar' %]
  1566.     ...
  1567.  
  1568.     [% TRY %]
  1569.        [% USE DBI(mydsn) %]
  1570.     [% CATCH %]
  1571.        ERROR! Type: [% error.type %]
  1572.               Info: [% error.info %]
  1573.     [% END %]
  1574.  
  1575. output (assuming a non-existant database called 'foobar'):
  1576.  
  1577.     ERROR!  Type: DBI
  1578.             Info: Unknown database "foobar"
  1579.  
  1580. The 'error' variable can also be specified by itself and will return a 
  1581. string of the form "$type error - $info".
  1582.  
  1583.     ...
  1584.     [% CATCH %]
  1585.     ERROR: [% error %]
  1586.     [% END %]
  1587.  
  1588. output:
  1589.  
  1590.     ERROR: DBI error - Unknown database "foobar"
  1591.  
  1592. Each CATCH block may be specified with a particular exception type
  1593. denoting the kind of error that it should catch.  Multiple CATCH
  1594. blocks can be provided to handle different types of exception that may
  1595. be thrown in the TRY block.  A CATCH block specified without any type,
  1596. as in the previous example, is a default handler which will catch any
  1597. otherwise uncaught exceptions.  This can also be specified as 
  1598. [% CATCH DEFAULT %].
  1599.  
  1600.     [% TRY %]
  1601.        [% INCLUDE myfile %]
  1602.        [% USE DBI(mydsn) %]
  1603.        [% CALL somecode %]
  1604.        ...
  1605.     [% CATCH file %]
  1606.        File Error! [% error.info %]
  1607.     [% CATCH DBI %]
  1608.        [% INCLUDE database/error.html %]
  1609.     [% CATCH %]
  1610.        [% error %]
  1611.     [% END %]
  1612.  
  1613. Remember that you can specify multiple directives within a single tag,
  1614. each delimited by ';'.  Thus, you might prefer to write your simple
  1615. CATCH blocks more succinctly as:
  1616.  
  1617.     [% TRY %]
  1618.        ...
  1619.     [% CATCH file; "File Error! $error.info" %]
  1620.     [% CATCH DBI;  INCLUDE database/error.html %]
  1621.     [% CATCH; error %]
  1622.     [% END %]
  1623.  
  1624. or even:
  1625.  
  1626.     [% TRY %]
  1627.        ...
  1628.     [% CATCH file ;
  1629.            "File Error! $error.info" ;
  1630.        CATCH DBI ;
  1631.        INCLUDE database/error.html ;
  1632.        CATCH ;
  1633.        error ;
  1634.        END
  1635.     %]
  1636.  
  1637. The DBI plugin throws exceptions of the 'DBI' type (in case that
  1638. wasn't already obvious).  The other specific exception caught here is
  1639. of the 'file' type.
  1640.  
  1641. A 'file' error is automatically thrown by the Template Toolkit when it
  1642. can't find a file, or fails to load, parse or process a file that has
  1643. been requested by an INCLUDE, PROCESS, INSERT or WRAPPER directive.
  1644. If 'myfile' can't be found in the example above, the [% INCLUDE myfile
  1645. %] directive will raise a 'file' exception which is then caught by the
  1646. [% CATCH file %] block, generating the output:
  1647.  
  1648.     File Error! myfile: not found
  1649.  
  1650. Note that the DEFAULT option (disabled by default) allows you to
  1651. specify a default file to be used any time a template file can't be
  1652. found.  This will prevent file exceptions from ever being raised when
  1653. a non-existant file is requested (unless, of course, the DEFAULT file
  1654. doesn't exist).  Errors encountered once the file has been found
  1655. (i.e. read error, parse error) will be raised as file exceptions as per
  1656. usual.
  1657.  
  1658. Uncaught exceptions (i.e. the TRY block doesn't have a type specific
  1659. or default CATCH handler) may be caught by enclosing TRY blocks which
  1660. can be nested indefinitely across multiple templates.  If the error
  1661. isn't caught at any level then processing will stop and the Template
  1662. process() method will return a false value to the caller.  The
  1663. relevant Template::Exception object can be retrieved by calling the
  1664. error() method.
  1665.  
  1666.     [% TRY %]
  1667.        ...
  1668.        [% TRY %]
  1669.           [% INCLUDE $user.header %]
  1670.        [% CATCH file %]
  1671.       [% INCLUDE header %]
  1672.        [% END %]
  1673.        ...
  1674.     [% CATCH DBI %]
  1675.        [% INCLUDE database/error.html %]
  1676.     [% END %]
  1677.  
  1678. In this example, the inner TRY block is used to ensure that the first
  1679. INCLUDE directive works as expected.  We're using a variable to
  1680. provide the name of the template we want to include, user.header, and
  1681. it's possible this contains the name of a non-existant template, or
  1682. perhaps one containing invalid template directives.  If the INCLUDE fails
  1683.  with a 'file' error then we CATCH it in the inner block and INCLUDE
  1684. the default 'header' file instead.  Any DBI errors that occur within
  1685. the scope of the outer TRY block will be caught in the relevant CATCH
  1686. block, causing the 'database/error.html' template to be processed.
  1687. Note that included templates inherit all currently defined template
  1688. variable so these error files can quite happily access the 'error'
  1689. variable to retrieve information about the currently caught exception.
  1690. e.g.
  1691.  
  1692. 'database/error.html':
  1693.  
  1694.     <h2>Database Error</h2>
  1695.     A database error has occurred: [% error.info %]
  1696.  
  1697. You can also specify a FINAL block.  This is always processed
  1698. regardless of the outcome of the TRY and/or CATCH block.  If an
  1699. exception is uncaught then the FINAL block is processed before jumping
  1700. to the enclosing block or returning to the caller.
  1701.  
  1702.     [% TRY %]
  1703.        ...
  1704.     [% CATCH this %] 
  1705.        ...
  1706.     [% CATCH that %] 
  1707.        ...
  1708.     [% FINAL %]
  1709.        All done!
  1710.     [% END %]
  1711.  
  1712. The output from the TRY block is left intact up to the point where an
  1713. exception occurs.  For example, this template:
  1714.  
  1715.     [% TRY %]
  1716.        This gets printed 
  1717.        [% THROW food 'carrots' %]
  1718.        This doesn't
  1719.     [% CATCH food %]
  1720.        culinary delights: [% error.info %]
  1721.     [% END %]    
  1722.  
  1723. generates the following output:
  1724.  
  1725.     This gets printed
  1726.     culinary delights: carrots
  1727.  
  1728. The CLEAR directive can be used in a CATCH or FINAL block to clear
  1729. any output created in the TRY block.
  1730.  
  1731.     [% TRY %]
  1732.        This gets printed 
  1733.        [% THROW food 'carrots' %]
  1734.        This doesn't
  1735.     [% CATCH food %]
  1736.        [% CLEAR %]
  1737.        culinary delights: [% error.info %]
  1738.     [% END %]    
  1739.  
  1740. output:
  1741.  
  1742.     culinary delights: carrots
  1743.  
  1744. Exception types are hierarchical, with each level being separated by
  1745. the familiar dot operator.  A 'DBI.connect' exception is a more
  1746. specific kind of 'DBI' error.  Similarly, a 'myown.error.barf' is a
  1747. more specific kind of 'myown.error' type which itself is also a
  1748. 'myown' error.  A CATCH handler that specifies a general exception
  1749. type (such as 'DBI' or 'myown.error') will also catch more specific
  1750. types that have the same prefix as long as a more specific handler
  1751. isn't defined.  Note that the order in which CATCH handlers are
  1752. defined is irrelevant; a more specific handler will always catch an
  1753. exception in preference to a more generic or default one.
  1754.  
  1755.     [% TRY %]
  1756.        ...
  1757.     [% CATCH DBI ;
  1758.          INCLUDE database/error.html ;
  1759.        CATCH DBI.connect ;
  1760.          INCLUDE database/connect.html ;
  1761.        CATCH ; 
  1762.          INCLUDE error.html ;
  1763.        END
  1764.     %]
  1765.  
  1766. In this example, a 'DBI.connect' error has it's own handler, a more
  1767. general 'DBI' block is used for all other DBI or DBI.* errors and a 
  1768. default handler catches everything else.
  1769.  
  1770. Exceptions can be raised in a template using the THROW directive.  The
  1771. first parameter is the exception type which doesn't need to be quoted
  1772. (but can be, it's the same as INCLUDE) followed by the relevant error
  1773. message which can be any regular value such as a quoted string,
  1774. variable, etc.
  1775.  
  1776.     [% THROW food "Missing ingredients: $recipe.error" %]
  1777.  
  1778.     [% THROW user.login 'no user id: please login' %]
  1779.  
  1780.     [% THROW $myerror.type "My Error: $myerror.info" %]
  1781.  
  1782. It's also possible to specify additional positional or named 
  1783. parameters to the THROW directive if you want to pass more than 
  1784. just a simple message back as the error info field.  
  1785.  
  1786.     [% THROW food 'eggs' 'flour' msg='Missing Ingredients' %]
  1787.  
  1788. In this case, the error 'info' field will be a hash array containing
  1789. the named arguments, in this case 'msg' =E<gt> 'Missing Ingredients',
  1790. and an 'args' item which contains a list of the positional arguments, 
  1791. in this case 'eggs' and 'flour'.  The error 'type' field remains 
  1792. unchanged, here set to 'food'.
  1793.  
  1794.     [% CATCH food %]
  1795.        [% error.info.msg %]
  1796.        [% FOREACH item = error.info.args %]
  1797.           * [% item %]
  1798.        [% END %]
  1799.     [% END %]
  1800.  
  1801. This produces the output:
  1802.  
  1803.        Missing Ingredients
  1804.          * eggs
  1805.          * flour
  1806.  
  1807. In addition to specifying individual positional arguments as
  1808. [% error.info.args.n %], the 'info' hash contains keys directly 
  1809. pointing to the positional arguments, as a convenient shortcut.
  1810.  
  1811.     [% error.info.0 %]   # same as [% error.info.args.0 %]
  1812.  
  1813. Exceptions can also be thrown from Perl code which you've bound to
  1814. template variables, or defined as a plugin or other extension.  To
  1815. raise an exception, call die() passing a reference to a
  1816. Template::Exception object as the argument.  This will then be caught
  1817. by any enclosing TRY blocks from where the code was called.
  1818.  
  1819.     use Template::Exception;
  1820.     ...
  1821.  
  1822.     my $vars = {
  1823.     foo => sub {
  1824.         # ... do something ...
  1825.         die Template::Exception->new('myerr.naughty',
  1826.                      'Bad, bad error');
  1827.         },
  1828.     };
  1829.  
  1830. template:
  1831.  
  1832.     [% TRY %]
  1833.        ...
  1834.        [% foo %]
  1835.        ...   
  1836.     [% CATCH myerr ;
  1837.          "Error: $error" ;
  1838.        END
  1839.     %]
  1840.  
  1841. output:
  1842.  
  1843.     Error: myerr.naughty error - Bad, bad error
  1844.  
  1845. The 'info' field can also be a reference to another object or data
  1846. structure, if required.
  1847.  
  1848.     die Template::Exception->new('myerror', { 
  1849.     module => 'foo.pl', 
  1850.     errors => [ 'bad permissions', 'naughty boy' ],
  1851.     });
  1852.  
  1853. Later, in a template:
  1854.  
  1855.     [% TRY %]
  1856.        ...
  1857.     [% CATCH myerror %]
  1858.        [% error.info.errors.size or 'no';
  1859.           error.info.errors.size == 1 ? ' error' : ' errors' %]
  1860.        in [% error.info.module %]: 
  1861.           [% error.info.errors.join(', ') %].
  1862.     [% END %]
  1863.  
  1864. Generating the output:
  1865.  
  1866.        2 errors in foo.pl:
  1867.           bad permissions, naughty boy.
  1868.  
  1869. You can also call die() with a single string, as is common in much 
  1870. existing Perl code.  This will automatically be converted to an 
  1871. exception of the 'undef' type (that's the literal string 'undef', 
  1872. not the undefined value).  If the string isn't terminated with a 
  1873. newline then Perl will append the familiar " at $file line $line"
  1874. message.
  1875.  
  1876.     sub foo {
  1877.     # ... do something ...
  1878.     die "I'm sorry, Dave, I can't do that\n";
  1879.     }
  1880.  
  1881. If you're writing a plugin, or some extension code that has the
  1882. current Template::Context in scope (you can safely skip this section
  1883. if this means nothing to you) then you can also raise an exception by
  1884. calling the context throw() method.  You can pass it an
  1885. Template::Exception object reference, a pair of ($type, $info) parameters
  1886. or just an $info string to create an exception of 'undef' type.
  1887.  
  1888.     $context->throw($e);        # exception object
  1889.     $context->throw('Denied');        # 'undef' type
  1890.     $context->throw('user.passwd', 'Bad Password');
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898. =item NEXT
  1899.  
  1900. The NEXT directive can be used to start the next iteration of a FOREACH 
  1901. or WHILE loop.
  1902.  
  1903.     [% FOREACH user = userlist %]
  1904.        [% NEXT IF user.isguest %]
  1905.        Name: [% user.name %]    Email: [% user.email %]
  1906.     [% END %]
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912. =item LAST
  1913.  
  1914. The LAST directive can be used to prematurely exit a FOREACH or WHILE
  1915. loop.
  1916.  
  1917.     [% FOREACH user = userlist %]
  1918.        Name: [% user.name %]    Email: [% user.email %]
  1919.        [% LAST IF some.condition %]
  1920.     [% END %]
  1921.  
  1922. BREAK can also be used as an alias for LAST.
  1923.  
  1924.  
  1925.  
  1926.  
  1927. =item RETURN
  1928.  
  1929. The RETURN directive can be used to stop processing the current
  1930. template and return to the template from which it was called, resuming
  1931. processing at the point immediately after the INCLUDE, PROCESS or
  1932. WRAPPER directive.  If there is no enclosing template then the
  1933. Template process() method will return to the calling code with a 
  1934. true value.
  1935.  
  1936.     Before
  1937.     [% INCLUDE half_wit %]
  1938.     After
  1939.   
  1940.     [% BLOCK half_wit %]
  1941.     This is just half...
  1942.     [% RETURN %]
  1943.     ...a complete block
  1944.     [% END %]
  1945.  
  1946. output:
  1947.  
  1948.     Before
  1949.     This is just half...
  1950.     After
  1951.  
  1952.  
  1953.  
  1954.  
  1955. =item STOP
  1956.  
  1957. The STOP directive can be used to indicate that the processor should
  1958. stop gracefully without processing any more of the template document.
  1959. This is a planned stop and the Template process() method will return a
  1960. B<true> value to the caller.  This indicates that the template was
  1961. processed successfully according to the directives within it.
  1962.  
  1963.     [% IF something.terrible.happened %]
  1964.        [% INCLUDE fatal/error.html %]
  1965.        [% STOP %]
  1966.     [% END %]
  1967.  
  1968.     [% TRY %]
  1969.        [% USE DBI(mydsn) %]
  1970.        ...
  1971.     [% CATCH DBI.connect %]
  1972.        <p>Cannot connect to the database: [% error.info %]</p>
  1973.        <br>
  1974.        We apologise for the inconvenience.  The cleaning lady 
  1975.        has removed the server power to plug in her vacuum cleaner.
  1976.        Please try again later.
  1977.        </p>
  1978.        [% INCLUDE footer %]
  1979.        [% STOP %]
  1980.     [% END %]
  1981.  
  1982.  
  1983.  
  1984.  
  1985. =item CLEAR
  1986.  
  1987. The CLEAR directive can be used to clear the output buffer for the current
  1988. enclosing block.   It is most commonly used to clear the output generated
  1989. from a TRY block up to the point where the error occurred.
  1990.  
  1991.     [% TRY %]
  1992.        blah blah blah            # this is normally left intact
  1993.        [% THROW some 'error' %]  # up to the point of error
  1994.        ...
  1995.     [% CATCH %]
  1996.        [% CLEAR %]               # clear the TRY output
  1997.        [% error %]               # print error string
  1998.     [% END %]
  1999.  
  2000.  
  2001.  
  2002.  
  2003. =back
  2004.  
  2005. =head2 Miscellaneous
  2006.  
  2007. =over 4
  2008.  
  2009.  
  2010. =item META
  2011.  
  2012. The META directive allows simple metadata items to be defined within a 
  2013. template.  These are evaluated when the template is parsed and as such
  2014. may only contain simple values (e.g. it's not possible to interpolate 
  2015. other variables values into META variables).
  2016.  
  2017.     [% META
  2018.        title   = 'The Cat in the Hat'
  2019.        author  = 'Dr. Seuss'
  2020.        version = 1.23 
  2021.     %]
  2022.  
  2023. The 'template' variable contains a reference to the main template 
  2024. being processed.  These metadata items may be retrieved as attributes
  2025. of the template.  
  2026.  
  2027.     <h1>[% template.title %]</h1>
  2028.     <h2>[% template.author %]</h2>
  2029.  
  2030. The 'name' and 'modtime' metadata items are automatically defined for
  2031. each template to contain its name and modification time in seconds
  2032. since the epoch.
  2033.  
  2034.     [% USE date %]        # use Date plugin to format time
  2035.     ...
  2036.     [% template.name %] last modified
  2037.     at [% date.format(template.modtime) %]
  2038.  
  2039. The PRE_PROCESS and POST_PROCESS options allow common headers and 
  2040. footers to be added to all templates.  The 'template' reference is
  2041. correctly defined when these templates are processed, allowing headers
  2042. and footers to reference metadata items from the main template.
  2043.  
  2044.     $template = Template->new({
  2045.     PRE_PROCESS  => 'header',
  2046.     POST_PROCESS => 'footer',
  2047.     });
  2048.  
  2049.     $template->process('cat_in_hat');
  2050.  
  2051. header:
  2052.  
  2053.     <html>
  2054.     <head>
  2055.     <title>[% template.title %]</title>
  2056.     </head>
  2057.     <body>
  2058.  
  2059. cat_in_hat:
  2060.  
  2061.     [% META
  2062.        title   = 'The Cat in the Hat'
  2063.        author  = 'Dr. Seuss'
  2064.        version = 1.23 
  2065.        year    = 2000
  2066.     %]
  2067.  
  2068.     The cat in the hat sat on the mat.
  2069.  
  2070. footer:
  2071.  
  2072.     <hr>
  2073.     © [% template.year %] [% template.author %]
  2074.     </body>
  2075.     </html>
  2076.  
  2077. The output generated from the above example is:
  2078.  
  2079.     <html>
  2080.     <head>
  2081.     <title>The Cat in the Hat</title>
  2082.     </head>
  2083.     <body>
  2084.  
  2085.     The cat in the hat sat on the mat.
  2086.  
  2087.     <hr>
  2088.     © 2000 Dr. Seuss
  2089.     </body>
  2090.     </html>
  2091.  
  2092.  
  2093.  
  2094. =item TAGS
  2095.  
  2096. The TAGS directive can be used to set the START_TAG and END_TAG values
  2097. on a per-template file basis.
  2098.  
  2099.     [% TAGS <+ +> %]
  2100.  
  2101.     <+ INCLUDE header +>
  2102.  
  2103. The TAGS directive may also be used to set a named TAG_STYLE
  2104.  
  2105.     [% TAGS html %]
  2106.     <!-- INCLUDE header -->
  2107.  
  2108. See the TAGS and TAG_STYLE configuration options for further details.
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117. =item DEBUG
  2118.  
  2119. The DEBUG directive can be used to enable or disable directive debug
  2120. messages within a template.  The DEBUG configuration option must be
  2121. set to include DEBUG_DIRS for the DEBUG directives to have any effect.
  2122. If DEBUG_DIRS is not set then the parser will automatically ignore and
  2123. remove any DEBUG directives.
  2124.  
  2125. The DEBUG directive can be used with an 'on' or 'off' parameter to
  2126. enable or disable directive debugging messages from that point
  2127. forward.  When enabled, the output of each directive in the generated
  2128. output will be prefixed by a comment indicate the file, line and
  2129. original directive text.
  2130.  
  2131.     [% DEBUG on %]
  2132.     directive debugging is on (assuming DEBUG option is set true)
  2133.     [% DEBUG off %]
  2134.     directive debugging is off
  2135.  
  2136. The 'format' parameter can be used to change the format of the debugging
  2137. message.
  2138.  
  2139.     [% DEBUG format '<!-- $file line $line : [% $text %] -->' %]
  2140.  
  2141.  
  2142.     
  2143.  
  2144.  
  2145. =back
  2146.  
  2147. =head1 AUTHOR
  2148.  
  2149. Andy Wardley E<lt>abw@andywardley.comE<gt>
  2150.  
  2151. L<http://www.andywardley.com/|http://www.andywardley.com/>
  2152.  
  2153.  
  2154.  
  2155.  
  2156. =head1 VERSION
  2157.  
  2158. Template Toolkit version 2.13, released on 30 January 2004.
  2159.  
  2160. =head1 COPYRIGHT
  2161.  
  2162.   Copyright (C) 1996-2004 Andy Wardley.  All Rights Reserved.
  2163.   Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
  2164.  
  2165. This module is free software; you can redistribute it and/or
  2166. modify it under the same terms as Perl itself.
  2167.  
  2168.  
  2169.  
  2170. =cut
  2171.  
  2172. # Local Variables:
  2173. # mode: perl
  2174. # perl-indent-level: 4
  2175. # indent-tabs-mode: nil
  2176. # End:
  2177. #
  2178. # vim: expandtab shiftwidth=4:
  2179.