PHP HTML GENERATOR
Create HTML tags and render them efficiently., (*1)
Build status:
* Master
* Dev , (*2)
Overview
return HtmlTag::createElement();
// returns an empty HtmlTag Container
```php
return HtmlTag::createElement('a');
// returns an HtmlTag containing a 'a' tag, (*3)
### Why you should use it
- it always generates valid HTML and XHTML code
- it makes templates cleaner
- it's easy to use and fast to execute
## Render tags
```php
echo(HtmlTag::createElement('a'));
or, (*4)
$tag = HtmlTag::createElement('a')
echo( $tag );
echo HtmlTag::createElement('div');
```html
, (*5)
```php
echo(HtmlTag::createElement('p')->text('some content'));
```html
, (*6)
some content, (*7)
### Structured tags
```php
echo(HtmlTag::createElement('div')->addElement('a')->text('a text'));
```html
, (*8)
```php
$container = HtmlTag::createElement('div');
$container->addElement('p')->text('a text');
$container->addElement('a')->text('a link');
```html
, (*9)
### Attributes
#### Classics attributes (method : 'set')
```php
$tag = HtmlTag::createElement('a')
->set('href','./sample.php')
->set('id','myID')
->text('my link');
echo( $tag );
```html
my link, (*11)
#### Shortcut to set an ID attribute (method : 'id')
```php
$tag = HtmlTag::createElement('div')
->id('myID');
echo( $tag );
```html
, (*12)
my link
#### Class management (method : 'addClass'/'removeClass')
```php
$tag = HtmlTag::createElement('div')
->addClass('oneClass')
->text('my content')
echo( $tag );
```html
, (*13)
my content
```php
$tag = HtmlTag::createElement('div')
->addClass('aClass')
->addClass('anothereClass')
->text('my content')
echo( $tag );
```html
, (*14)
my content
```php
$tag = HtmlTag::createElement('div')
->addClass('firstClass')
->addClass('secondClass')
->text('my content')
->removeClass('firstClass');
echo( $tag );
```html
, (*15)
my content
### More
Text and content are generated according to the order of addition
```php
$tag = HtmlTag::createElement('p')
->text('a text')
->addElement('a')
->text('a link');
```html
, (*16)
ma texta link, (*17)
To generate content before text, 2 solutions :
```php
$tag = HtmlTag::createElement('p')
->addElement('a')
->text('a link')
->getParent()
->text('a text');
or, (*18)
$tag = HtmlTag::createElement('p');
$tag->addElement('a')->text('a link');
$tag->text('a text');
<p><a>a link</a>a text</p>