felixdorn / tag
Generates HTML in a clean and convenient syntax.
2.1.0
2022-09-09 11:08 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9
- illuminate/macroable: ^9
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v2.19.3
- pestphp/pest: ^v1.22
- phpstan/phpstan: ^1.8.5
README
Getting started
You can install the package via composer, if you don't have composer, you can download it here:
composer require felixdorn/tag
Or by adding a requirement in your composer.json:
{ "require": { "felixdorn/tag": "^2.0.0" } }
Usage
$tag = tag('div') ->class('container') ->children( tag('h1')->children('Title'), 'Some raw content' );
Adding attributes
We use the magic method __call
to add attributes. You can add any attribute you want.
tag('div') ->class('alert alert-danger') ->children('Something went wrong');
To add attributes containing a dash like aria-hidden
, use the equivalent in camel case (ariaHidden). We'll do the conversion back to kebab case when rendering the tag.
You can also assign multiple attributes at once.
tag('div') ->attributes([ 'id' => 'my-div', 'class' => 'mt-2' ]);
Nested tags
tag('div') ->class('container') ->children( tag('h1')->children('Some text') ); tag('div') ->children([ tag('h1')->children( tag('span')->children('Hello'), tag('b')->children('World'), ), tag('br'), tag('h3')->children('Whatever') ]);
Credits
License
This project is MIT Licensed.