waughj/html-attribute-list

A list o’ HTML attributes for easy HTML generation.

Installs: 320

Dependents: 6

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:project

pkg:composer/waughj/html-attribute-list

v1.2.0 2019-06-03 18:53 UTC

This package is auto-updated.

Last update: 2025-09-29 02:07:24 UTC


README

A list o’ HTML attributes for easy HTML generation.

Just create an instance with a hash map with attribute names as keys & attribute values as values:

$attribute_list = new HTMLAttributeList
([
    'class' => 'footer',
    'id' => 'main-footer'
]);

& using it as a string or calling getAttributesText() will automatically give you HTML code for the attributes, starting with a space.

Use like this:

<footer<?= $attribute_list; ?></footer>

& it will give you this:

<footer class="footer" id="main-footer"></footer>

An optional 2nd argument allows you to give the object a whitelist o’ attribute keys, for an easy way to limit what attributes can be included:

$attribute_list = new HTMLAttributeList
(
    [
        'class' => 'footer',
        'id' => 'main-footer',
        'talk' => 'blah',
        'name' => 'jack'
    ],
    [
        'class',
        'id'
    ]
);

This will ignore the attributes ‘talk’ & ‘name’, giving the same HTML output as the last example.

Thus for any code that generates certain HTML tags, you can easily make a whitelist o’ valid attributes for that tag to apply to user-given attributes lists.

Changelog

1.2.0

  • Add methods for changing attribute values.

1.1.0

  • Add method for getting hash map o' attribute keys & values.

1.0.0

  • Initial stable version.