Template::Library::HTML - Template library for building basic HTML pages
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:
[% INCLUDE html/header %]
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
[% WRAPPER html/table %] . . . [% END %]
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.
[% INCLUDE html/header title = 'This is a Test' bgcol = '#ffffff' %]
Additional header items can be provided by explicitly setting the 'headers' variable, e.g.
[% headers = BLOCK %] <META name="description" content="Template Toolkit"> <META name="REVISIT-AFTER" content="14 days"> <META name="keywords" content="Templates, Web, ...etc..."> [% END %]
[% INCLUDE html/header title = 'This is a Test' bgcol = '#ffffff' %]
[% PROCESS html/header %]
...page content here...
[% PROCESS html/footer %]
[% WRAPPER html/page %]
...page content here...
[% END %]
Page content should be defined in the 'content' variable (e.g. via WRAPPER). Additional HTML headers should be defined in the 'headers' variable.
[% WRAPPER html/page headers = '<META name="keywords" content="foo, bar, ...">' %]
...page content here...
[% END %]
[% WRAPPER html/table pad=10 space=4 col='#404040' %] <tr> <td>Hello</td> <td>World</td> </tr> [% END %]
The following variables may be defined:
[% WRAPPER html/table %] [% WRAPPER html/row %] <td>Hello</td> <td>World</td> [% END %] [% END %]
The following variables may be defined:
[% WRAPPER html/table %] [% WRAPPER html/row %] [% INCLUDE html/cell FOREACH content = ['Hello', 'World'] %] [% END %] [% END %]
The following variables may be defined:
[% WRAPPER html/bar %] <td>Foo</td> <td>Bar</td> [% END %]
[% WRAPPER html/box %] Hello World! [% END %]
<http://www.andywardley.com/|http://www.andywardley.com/>
Copyright (C) 1996-2004 Andy Wardley. All Rights Reserved. Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |