Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/palmtreephp/html

:palm_tree: OOP style HTML elements and selectors
https://github.com/palmtreephp/html

composer-package html html-renderer php

Last synced: about 1 month ago
JSON representation

:palm_tree: OOP style HTML elements and selectors

Awesome Lists containing this project

README

        

# :palm_tree: Palmtree Html

[![License](http://img.shields.io/packagist/l/palmtree/form.svg)](LICENSE)
[![Build](https://img.shields.io/github/workflow/status/palmtreephp/html/Build.svg)](https://github.com/palmtreephp/html/actions/workflows/build.yml)

Build and render HTML elements using an OOP style interface and jQuery style selectors.

## Requirements
* PHP >= 7.1

## Installation

Use composer to add the package to your dependencies:
```bash
composer require palmtree/html
```

## Usage Example
```php
'Home',
'href' => 'https://example.org',
];

$menuItems[] = [
'label' => 'About',
'href' => 'https://example.org/about',
];

$menuItems[] = [
'label' => 'Contact',
'href' => 'https://example.org/contact',
];

foreach ($menuItems as $item) {
$a = Element::create('a[href="' . $item['href'] . '"]')->setInnerText($item['label']);

$li = Element::create('li.item')->addChild($a);
$li->classes[] = 'item-' . strtolower($item['label']);

$menu->addChild($li);
}

$menu->attributes->setData('item_total', (string)count($menuItems));
$menu->attributes['aria-label'] = 'Navigation'

echo $menu->render();

?>
```

Renders the following HTML:

```html


```

## License

Released under the [MIT license](LICENSE)