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"
}
}
$tag = tag('div')
->class('container')
->children(
tag('h1')->children('Title'),
'Some raw content'
);
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'
]);
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')
]);
This project is MIT Licensed.