ucscode / uss-element
UssElement is a PHP library for building and manipulating HTML elements programmatically.
Requires
- php: >=8.1
README
A PHP Library for Effortless HTML Generation (Package From User Synthetics)
Description:
UssElement is a powerful PHP library designed to simplify the process of building and manipulating HTML elements in your web applications. With UssElement, you can effortlessly create DOM nodes, set attributes, define content, and generate HTML strings with ease. Streamline your PHP-based web development workflow and save time when constructing dynamic and interactive web pages.
Key Features:
- Create HTML elements using PHP code.
- Set element attributes, such as class names and IDs.
- Define inner HTML content for elements.
- Generate HTML strings with the
UssElement::getHTML()
method. - Boost your productivity by simplifying HTML generation in PHP.
Installation (Composer)
You can include UssElement in your project using Composer:
composer require ucscode/uss-element
Getting Started:
- Instantiate the UssElement class with the desired HTML element type (e.g.,
UssElement::NODE_DIV
). - Use UssElement methods to set attributes and content.
- Generate HTML strings with
UssElement::getHTML()
for seamless integration into your web pages.
Example:
use Ucscode\UssElement\UssElement; // Create Elements $div = new UssElement(UssElement::NODE_DIV); $span = new UssElement(UssElement::NODE_SPAN); // Modify Elements $div->setAttribute('class', 'container'); $span->setAttribute('style', "color: red;"); $span->setContent("Hello world!"); // Organize Element $div->appendChild($span); // Generate and output HTML string echo $div->getHTML(true); // true to indent html output
Inquiry
But why use this over the default PHP DOMDocument
?
UssElement not only provides out of the box methods and concept but is prepared for ultimate future increase. The default DOMDocument uses methods that are similar to that of Javascript and nothing more. There are also maximized limitation like being unable to directly insert innerHTML
into your document context.
With UssElement, you can do all that and even more. For example, you can set the visibility of an element to render with other element or not.
$div->appendChild($span); $span->setInvisible(true);
In the above example, span is a child of div and always will be unless removed. However, when the content is rendered in HTML, the span element will be absent, giving you the ability to control the element visiblity without actually removing the element.
Methods
💖 Support
If you find UssElement helpful and would like to support its development and maintenance, you can make a donation.
Your contribution helps ensure the continued improvement and sustainability of this project.
Ways to Donate
- Bitcoin: You can also contribute with Bitcoin by sending to our Bitcoin wallet address:
bc1q22zymcsq9t7m9fdwau3dqcpme2szvgnzkqyjza
.
Note: UssElement is an open-source project, and contributions are voluntary. Donations are not tax-deductible.