[%# # 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 = 'Modules' page = 'Plugin_HTML' %] [% WRAPPER toc; PROCESS tocitem title ="SYNOPSIS" subs = []; PROCESS tocitem title ="DESCRIPTION" subs = []; PROCESS tocitem title ="METHODS" subs = [ "escape(text)", "attributes(hash)", "element(type, attributes)" ]; PROCESS tocitem title ="DEBUGGING" subs = []; 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="SYNOPSIS" -%]

        [% tt_start_tag %] USE HTML [% tt_end_tag %]

        [% tt_start_tag %] HTML.escape("if (a < b && c > d) ..." [% tt_end_tag %]

        [% tt_start_tag %] HTML.element(table => { border => 1, cellpadding => 2 }) [% tt_end_tag %]

        [% tt_start_tag %] HTML.attributes(border => 1, cellpadding => 2) [% tt_end_tag %]

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

The HTML plugin is very new and very basic, implementing a few useful methods for generating HTML. It is likely to be extended in the future or integrated with a larger project to generate HTML elements in a generic way (as discussed recently on the mod_perl mailing list).

[%- END %] [% WRAPPER section title="METHODS" -%][% WRAPPER subsection title = "escape(text)" -%]

Returns the source text with any HTML reserved characters such as <, >, etc., correctly esacped to their entity equivalents.

[%- END %] [% WRAPPER subsection title = "attributes(hash)" -%]

Returns the elements of the hash array passed by reference correctly formatted (e.g. values quoted and correctly escaped) as attributes for an HTML element.

[%- END %] [% WRAPPER subsection title = "element(type, attributes)" -%]

Generates an HTML element of the specified type and with the attributes provided as an optional hash array reference as the second argument or as named arguments.

        [% tt_start_tag %] HTML.element(table => { border => 1, cellpadding => 2 }) [% tt_end_tag %]
        [% tt_start_tag %] HTML.element('table', border=1, cellpadding=2) [% tt_end_tag %]
        [% tt_start_tag %] HTML.element(table => attribs) [% tt_end_tag %]

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

The HTML plugin accepts a 'sorted' option as a constructor argument which, when set to any true value, causes the attributes generated by the attributes() method (either directly or via element()) to be returned in sorted order. Order of attributes isn't important in HTML, but this is provided mainly for the purposes of debugging where it is useful to have attributes generated in a deterministic order rather than whatever order the hash happened to feel like returning the keys in.

        [% tt_start_tag %] USE HTML(sorted=1) [% tt_end_tag %]
        [% tt_start_tag %] HTML.element( foo => { charlie => 1, bravo => 2, alpha => 3 } ) [% tt_end_tag %]

generates:

        <foo alpha="3" bravo="2" charlie="1">

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

Andy Wardley <abw@wardley.org>

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

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

2.62, 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::Plugin', 'Template::Plugin') -%]

[%- END %]