https://github.com/felixdorn/tag
Generates HTML in a clean and convenient syntax.
https://github.com/felixdorn/tag
html oop package php-library
Last synced: 6 days ago
JSON representation
Generates HTML in a clean and convenient syntax.
- Host: GitHub
- URL: https://github.com/felixdorn/tag
- Owner: felixdorn
- License: mit
- Created: 2019-09-28T18:06:47.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-11T21:29:35.000Z (over 3 years ago)
- Last Synced: 2025-03-10T22:17:40.941Z (over 1 year ago)
- Topics: html, oop, package, php-library
- Language: PHP
- Homepage: https://packagist.org/packages/felixdorn/tag
- Size: 78.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# Tag


## Getting started
You can install the package via composer, if you don't have composer, you can download it [here](https://getcomposer.org/):
```bash
composer require felixdorn/tag
```
Or by adding a requirement in your composer.json:
```json
{
"require": {
"felixdorn/tag": "^2.0.0"
}
}
```
## Usage
```php
$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.
```php
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.
```php
tag('div')
->attributes([
'id' => 'my-div',
'class' => 'mt-2'
]);
```
### Nested tags
```php
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
* [Félix Dorn](mailto:github@felixdorn.fr)
## License
This project is MIT Licensed.