Htmlable
![Build Status][ico-build]
[
][link-scrutinizer]
, (*1)
Simple PHP library for abstraction and rendering of html elements., (*2)
Install
Via Composer, (*3)
``` bash
$ composer require joaorobertopb/htmlable, (*4)
## Usage
``` php
$div = new JoaoRobertoPB\Htmlable\Tag('div');
$div->add('Hello, Htmlable!');
$div->render();
- The html code will be printed by the method
render().
- To return the html code use the
toHtml() method.
Examples
An empty tag:, (*5)
``` php
$div = new Tag('div'); // Or $div = Tag::make('div');
$div->render();, (*6)
``` html
<div></div>
A plain tag with text contents:, (*7)
``` php
$h1 = new Tag('h1');
$h1->add("Header");
$h1->render();, (*8)
``` html
<h1>Header</h1>
A tag with multiple attributes:, (*9)
``` php
$a = new Tag('a');
$a->id = "example";
$a->href = "#";
$a->add("Link");
$a->render();, (*10)
//Or attributes via construct method, (*11)
$a = new Tag('a',['id'=>"example", 'href'=>"#"]);
$a->add("Link");
$a->render();, (*12)
``` html
<a id="example" href="#">Link</a>
A more complex structure:, (*13)
``` php
$div = new Tag('div',['class'=>"container"]);
$divRow = new Tag('div',['class'=>"row"]);
$divCol = new Tag('div',['class'=>"col-md-6"]);, (*14)
$divCol->add("Hello!");
$divRow->add($divCol);
$div->add($divRow);, (*15)
$div->render();, (*16)
``` html
<div class="container">
<div class="row">
<div class="col-md-6">
Hello!
</div>
</div>
</div>
Change log
Please see CHANGELOG for more information on what has changed recently., (*17)
Testing
bash
$ composer test, (*18)
Contributing
Please see CONTRIBUTING for details., (*19)
Credits
This package is inspired by this great book by @pablodalloglio. Here is a package I used as reference., (*20)
License
The MIT License (MIT). Please see License File for more information., (*21)