[%# # IMPORTANT NOTE # This documentation is generated automatically from source # templates. Any changes you make here may be lost. # # The 'docsrc' documentation source bundle is available for download # from http://www.template-toolkit.org/docs.html and contains all # the source templates, XML files, scripts, etc., from which the # documentation for the Template Toolkit is built. -%] [% META book = 'Library' page = 'HTML' %] [% WRAPPER toc; PROCESS tocitem title ="DESCRIPTION" subs = [ "Headers, Footers and Pages", "Tables, Bars and Boxes" ]; PROCESS tocitem title ="AUTHOR" subs = []; PROCESS tocitem title ="VERSION" subs = []; PROCESS tocitem title ="COPYRIGHT" subs = []; PROCESS tocitem title ="SEE ALSO" subs = []; END %] [% WRAPPER section title="DESCRIPTION" -%]

NOTE: This documentation is incomplete and may be incorrect in places.

The 'html' template library is distributed as part of the Template Toolkit. It can be found in the 'templates' sub-directory of the installation directory.

        use Template;

        my $tt2 = Template->new({
    	INCLUDE_PATH => '/usr/local/tt2/templates',
        });

For a portable way to determine the installation 'templates' directory, you can use the `'Template::Config->instdir()'` class method.

        use Template;

        my $tt2 = Template->new({
    	INCLUDE_PATH => Template::Config->instdir('templates'),
        });

You should now be able to access the html library as, for example:

        [% tt_start_tag %] INCLUDE html/header [% tt_end_tag %]

Note that some of the more basic elements don't give you much more than the raw HTML tags. In many cases you might be well advised to stick to regular HTML rather than complicating matters by the use of template elements.

e.g.

        <table>
          . . .
        </table>

vs

        [% tt_start_tag %] WRAPPER html/table [% tt_end_tag %]
           . . .
        [% tt_start_tag %] END [% tt_end_tag %]

However, the use of template elements to generate the underlying HTML does have some important benefits, particularly as the constructs start to get more complicated and more magical.

See the example in the 'examples' sub-directory of the distribution directory for further examples and enlightenment on using this library.

[% WRAPPER subsection title = "Headers, Footers and Pages" -%]

- header

  The 'header' element generates the regular header required as the pre-amble for an HTML document. That is, everything from the initial <html> to the opening <body>.

          [% tt_start_tag %] INCLUDE html/header
               title = 'This is a Test'
      	 bgcol = '#ffffff'
          [% tt_end_tag %]

  Additional header items can be provided by explicitly setting the 'headers' variable, e.g.

          [% tt_start_tag %] headers = BLOCK [% tt_end_tag %]
          <META name="description" content="Template Toolkit">
          <META name="REVISIT-AFTER" content="14 days">
          <META name="keywords" content="Templates, Web, ...etc...">
          [% tt_start_tag %] END [% tt_end_tag %]

          [% tt_start_tag %] INCLUDE html/header
      	 title = 'This is a Test'
      	 bgcol = '#ffffff'
          [% tt_end_tag %]

- footer

  The 'footer' element generates the terminating </body> and </html> element to balance the header.

          [% tt_start_tag %] PROCESS html/header [% tt_end_tag %]

          ...page content here...

          [% tt_start_tag %] PROCESS html/footer [% tt_end_tag %]

- page

  The 'page' element combines the 'html/header' and 'html/footer' elements.

          [% tt_start_tag %] WRAPPER html/page [% tt_end_tag %]

          ...page content here...

          [% tt_start_tag %] END [% tt_end_tag %]

  Page content should be defined in the 'content' variable (e.g. via WRAPPER). Additional HTML headers should be defined in the 'headers' variable.

          [% tt_start_tag %] WRAPPER html/page
              headers = '<META name="keywords" content="foo, bar, ...">'
          [% tt_end_tag %]

          ...page content here...

          [% tt_start_tag %] END [% tt_end_tag %]

[%- END %] [% WRAPPER subsection title = "Tables, Bars and Boxes" -%]

- table

  A basic element for creating HTML tables.

          [% tt_start_tag %] WRAPPER html/table pad=10 space=4 col='#404040' [% tt_end_tag %]
             <tr>
      	<td>Hello</td> <td>World</td>
             </tr>
          [% tt_start_tag %] END [% tt_end_tag %]

  The following variables may be defined:

  - border

    Set the border width (default: 0)

  - col

    Set the background colour (default: none).

  - width

    Set a fixed table width.

  - pad

    Set the cellpadding.

  - space

    Set the cellspacing.

  - content

    Content for the box. Supplied automatically if used via WRAPPER.

- row

  A basic element for creating HTML table rows.

          [% tt_start_tag %] WRAPPER html/table [% tt_end_tag %]
             [% tt_start_tag %] WRAPPER html/row [% tt_end_tag %]
      	<td>Hello</td> <td>World</td>
             [% tt_start_tag %] END [% tt_end_tag %]
          [% tt_start_tag %] END [% tt_end_tag %]

  The following variables may be defined:

  - col

    Set the background colour (default: none).

  - valign

    Set the vertical alignment.

  - rowspan

    Specify the number of rows to span.

  - content

    Content for the box. Supplied automatically if used via WRAPPER.

- cell

  A basic element for creating HTML table cells.

          [% tt_start_tag %] WRAPPER html/table [% tt_end_tag %]
             [% tt_start_tag %] WRAPPER html/row [% tt_end_tag %]
      	  [% tt_start_tag %] INCLUDE html/cell
      		FOREACH content = ['Hello', 'World'] [% tt_end_tag %]
             [% tt_start_tag %] END [% tt_end_tag %]
          [% tt_start_tag %] END [% tt_end_tag %]

  The following variables may be defined:

  - col

    Set the background colour (default: none).

  - align

    Set the horizontal alignment.

  - colspan

    Specify the number of columns to span.

  - content

    Content for the cell. Supplied automatically if used via WRAPPER.

- bar

  The bar element is a wrapping of html/table + html/row.

          [% tt_start_tag %] WRAPPER html/bar [% tt_end_tag %]
             <td>Foo</td>  <td>Bar</td>
          [% tt_start_tag %] END [% tt_end_tag %]

- box

  The box element is a wrapping of html/table + html/row + html/cell

          [% tt_start_tag %] WRAPPER html/box [% tt_end_tag %]
             Hello World!
          [% tt_start_tag %] END [% tt_end_tag %]

[%- END %] [%- END %] [% WRAPPER section title="AUTHOR" -%]

Andy Wardley <abw@wardley.org>

[% ttlink('http://wardley.org/', 'http://wardley.org/') -%]

[%- END %] [% WRAPPER section title="VERSION" -%]

2.68, distributed as part of the Template Toolkit version 2.19, released on 27 April 2007.

[%- END %] [% WRAPPER section title="COPYRIGHT" -%]

      Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

[%- END %] [% WRAPPER section title="SEE ALSO" -%]

[% ttlink('Template::Library::Splash', 'Template::Library::Splash') -%]

[%- END %]