Templat...n::HTML(3)
okay bestie, welcome to the Template::Plugin::HTML(3) page β User Contributed Perl Documentation β π this is the plugin for making HTML elements and doing cute little escape/attribute tasks. she's lowkey simple and highkey useful. no cap.
β¨ NAME β¨
Template::Plugin::HTML β Plugin to create HTML elements. that's the whole name section, periodt.
π¦ SYNOPSIS π¦
vibe check, you use it like this:
[% USE HTML %]
[% HTML.escape("if (a < b && c > d) ..." %]
[% HTML.element(table => { border => 1, cellpadding => 2 }) %]
[% HTML.attributes(border => 1, cellpadding => 2) %]
πΈ DESCRIPTION πΈ
The HTML plugin is a very basic plugin β like, she's not trying to be a whole framework β implementing a few useful methods for generating HTML. main character energy but make it minimal.
π METHODS π
each method is a little tool in her bag, bestie.
escape(text) π§Ό
Returns the source text with any HTML reserved characters such as <, >, etc., correctly escaped to their entity equivalents. so if your string is giving raw reserved-char chaos, she turns it into entities. slay.
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. so you hand her a hashref, she hands back attribute-ready text, all quoted and escaped. cute.
add_attribute(attributes) β
This provides a way to incrementally add attributes to the object. The values passed in are stored in the object. Calling element with just a tag or attributes and no parameters will use the saved attributes. it's giving sticking little accessories on your element, one at a time.
USE tag = HTML;
tag.add_attributes( { class => 'navbar' } );
tag.add_attributes( { id => 'foo' } );
tag.add_attributes( { class => 'active' } );
tag.element( 'li' ); # <li class="navbar active" id="foo">
This method has two aliases: add_attribute() and add(). so yes, she answers to multiple names, iykyk.
replace_attribute(attributes) π
This will replace an attribute value instead of adding to existing ones. so if a class is already saved, she swaps the value instead of stacking another one on top.
USE tag = HTML;
tag.add_attributes( { class => 'navbar' } );
tag.add_attributes( { id => 'foo' } );
tag.replace_attributes( { class => 'active' } );
tag.element( 'li' ); # <li class="active" id="foo">
This method has two aliases: replace_attribute() and replace().
clear_attributes π§Ή
Clears any saved attributes. poof, gone, no saved attrs left. fresh start, bestie.
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.
[% HTML.element(table => { border => 1, cellpadding => 2 }) %]
[% HTML.element('table', border=1, cellpadding=2) %]
[% HTML.element(table => attribs) %]
so you can pass a hashref as the second arg or use named arguments β either way she builds the element. iconic.
π 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. so it's a debug vibe, not an HTML rule. fr fr.
[% USE HTML(sorted=1) %]
[% HTML.element( foo => { charlie => 1, bravo => 2, alpha => 3 } ) %]
generates:
<foo alpha="3" bravo="2" charlie="1">
π AUTHOR π
the author credit is exactly: Andy Wardley <abw@wardley.org> <http://wardley.org/>. iconic, no cap.
π«Ά COPYRIGHT π«Ά
Copyright (C) 1996-2022 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.
π SEE ALSO π
Template::Plugin β that's the reference, go peek. bestie behavior.
that's the whole page π source/version: perl v5.42.0; date: 2024-06-23; manual tag: Templat...n::HTML(3). bye and slay your HTML β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Template-Toolkit 3.102.0-bp160.1.13 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms