1Template::Plugin::HTML(U3s)er Contributed Perl DocumentatTieomnplate::Plugin::HTML(3)
2
3
4

NAME

6       Template::Plugin::HTML - Plugin to create HTML elements
7

SYNOPSIS

9           [% USE HTML %]
10
11           [% HTML.escape("if (a < b && c > d) ..." %]
12
13           [% HTML.element(table => { border => 1, cellpadding => 2 }) %]
14
15           [% HTML.attributes(border => 1, cellpadding => 2) %]
16

DESCRIPTION

18       The "HTML" plugin is a very basic plugin, implementing a few useful
19       methods for generating HTML.
20

METHODS

22   escape(text)
23       Returns the source text with any HTML reserved characters such as "<",
24       ">", etc., correctly escaped to their entity equivalents.
25
26   attributes(hash)
27       Returns the elements of the hash array passed by reference correctly
28       formatted (e.g. values quoted and correctly escaped) as attributes for
29       an HTML element.
30
31   add_attribute(attributes)
32       This provides a way to incrementally add attributes to the object.  The
33       values passed in are stored in the object.  Calling element with just a
34       tag or attributes without an parameters will used the saved attributes.
35
36           USE tag = HTML;
37           tag.add_attributes( { class => 'navbar' } );
38           tag.add_attributes( { id => 'foo' } );
39           tag.add_attributes( { class => 'active' } );
40
41           tag.element( 'li' ); # <li class="navbar active" id="foo">
42
43       This method has two aliases: add_attribute() and add().
44
45   replace_attribute(attributes)
46       This will replace an attribute value instead of add to existing.
47
48           USE tag = HTML;
49           tag.add_attributes( { class => 'navbar' } );
50           tag.add_attributes( { id => 'foo' } );
51           tag.replace_attributes( { class => 'active' } );
52
53           tag.element( 'li' ); # <li class="active" id="foo">
54
55       This method has two aliases: replace_attribute() and replace().
56
57   clear_attributes
58       Clears any saved attributes
59
60   element(type, attributes)
61       Generates an HTML element of the specified type and with the attributes
62       provided as an optional hash array reference as the second argument or
63       as named arguments.
64
65           [% HTML.element(table => { border => 1, cellpadding => 2 }) %]
66           [% HTML.element('table', border=1, cellpadding=2) %]
67           [% HTML.element(table => attribs) %]
68

DEBUGGING

70       The HTML plugin accepts a "sorted" option as a constructor argument
71       which, when set to any true value, causes the attributes generated by
72       the "attributes()" method (either directly or via "element()") to be
73       returned in sorted order.  Order of attributes isn't important in HTML,
74       but this is provided mainly for the purposes of debugging where it is
75       useful to have attributes generated in a deterministic order rather
76       than whatever order the hash happened to feel like returning the keys
77       in.
78
79           [% USE HTML(sorted=1) %]
80           [% HTML.element( foo => { charlie => 1, bravo => 2, alpha => 3 } ) %]
81
82       generates:
83
84           <foo alpha="3" bravo="2" charlie="1">
85

AUTHOR

87       Andy Wardley <abw@wardley.org> <http://wardley.org/>
88
90       Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
91
92       This module is free software; you can redistribute it and/or modify it
93       under the same terms as Perl itself.
94

SEE ALSO

96       Template::Plugin
97
98
99
100perl v5.32.0                      2020-07-28         Template::Plugin::HTML(3)
Impressum