PHP code example of palmtree / html

1. Go to this page and download the library: Download palmtree/html library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

palmtree / html example snippets



use Palmtree\Html\Element;

$menu = new Element('ul.some-class');

$menuItems = [];

$menuItems[] = [
    'label' => '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();