kyleblanker / html-builder
Simple html builder.
v1.0.0
2017-01-13 18:27 UTC
Requires (Dev)
- phpunit/phpunit: 5.7.*
This package is not auto-updated.
Last update: 2024-10-26 21:03:50 UTC
README
Lightweight html builder
Examples
Creating a basic element
$builder = new \KyleBlanker\HtmlBuilder\Builder(); $element = $builder->element('p','Hello world'); echo $element->render();
Creating a basic element with an attribute
$builder = new \KyleBlanker\HtmlBuilder\Builder(); $element = $builder->element('p','Hello World')->attribute('style','color: #ff0000');
Nesting elements
$builder = new \KyleBlanker\HtmlBuilder\Builder(); $element = $builder->element('div')->nest(function($builder){ $builder->element('p','This element is nested'); });
Adding child elements
$builder = new \KyleBlanker\HtmlBuilder\Builder(); $parent = $builder->element('div'); $childElement = $builder->element('p'); $parent->child($childElement);
Creating an html document
$builder = new \KyleBlanker\HtmlBuilder\Builder(); $document = $builder->createDocument(); $document->getHead()->nest(function($builder){ $builder->element('title','Page Title'); }); $document->getBody()->nest(function($builder){ $builder->element('div')->attribute('style','background: #ff0000'); }); echo $document->build();