zamasskin / html-constructor
Html engine components
v1.0
2023-05-29 18:13 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 9.5.x-dev
This package is auto-updated.
Last update: 2025-05-29 01:27:00 UTC
README
Instead of writing HTML or using an HTML templating engine, you compose your layout using PHP structures with the dash-html-components library.
Installation
Install composer.
Run the following in the root of your project:
composer require zamasskin/html-constructor dev-main
Or, create a composer.json file with the following contents and run "composer install":
{ "require": { "zamasskin/html-constructor": "dev-main" } }
Usage
<?php use HtmlConstructor\Tags; require_once "vendor/autoload.php"; $html = (new Tags\TextContent\Div()) ->style("color: red; background: #000") ->className("parent") ->children([ (new Tags\TextContent\Div())->className("one"), (new Tags\TextContent\Div())->className("two"), ]); echo $html->render(); // <div style="color: red; background: #000" class="parent"><div class="one"></div><div class="two"></div></div> $html = Tags::Div()->className("root")->children([ Tags::Span('main caption')->className("caption"), Tags::A('http://example.com', 'main link')->className("link") ]); echo $html->render(); // <div class="root"><span class="caption">main caption</span><a href="http://example.com" class="link">main link</a></div> $html = (new Tags\Tag("custom"))->setAttribute("data", "test"); echo $html->render(); // <custom data="%test"></custom> $html = Tags::Tag("custom")->setAttribute("data", "test"); echo $html->render(); // <custom data="%test"></custom>