Simple class to create Html Tags/Elements.
Bringing more redering to the client-side can sink your performance also loose pagespeed in your FMP and FCP. This is a usefull helper for all PHP Front-End and Back-End developers out there trying to bring their PHP code back to the Front again. It uses the basics of an OOP Programming in PHP to make your HTML layout managable, heritable and independent. (Componentwise or Snippet if you may)
- Manage all your Elements over namespaces, from simple HTML-Elements to complex constructions, call them and render them with a simple new class instance.
- Do not break your PHP code and to embed inbeetween Html or JS. Create small snippets and print from one variable.
- Manage globally you entire application using heritance, designing a layout that responses to any change.
- Also if your apllication already runs on PHP you may have lots of resources (like Routing, locale, Translations...) that will not be available in the front and it gets very complicated to get them into an Javascript or frameworks like React.js or Vue.js.
- Creating small components in PHP to be parsed by Javascript or any JS Framework allows to use you full PHP Potencial it will possible to write frontend code in PHP and use it on the clientside. More to that cooming soon...
- Gut clean possiblity for Meaningful-Names and file documentation the way we all know it in PHP. In Beetween Modeling and
PHP 7
- PHP WebApp: Download and Copy Element.php to your project depending on your namespacing include the file into a namespaced file and create a class extending it.
- WordPress: Include file to your Theme or any Plugin (Plugin and Explanation coming soon...)
<?php
// print a simple Link
$link = new Element('a', 'Click here');
$link->setAttr('href', '/');
echo $link;
// Or create your Link template
class Button extends Element {
public function __construct($content = false, $url = false) {
parent::__construct('a', $content, 'button');
if ($url) {
$this->setAttr('href', $url);
}
$this->setClass('button');
}
}
// print adding your defined values like content and the url
$button = new Button('Click here', '/');
// or maybe you decide in the view or your template to add some content
if (TRUE) {
$button->setContent(' NOW!');
}
echo $button;
// or Print it in one line if you like
echo new Button('Click here', '/');PHP-OOP-HTML-Tag-Element is licensed under the MIT License.