hipnaba/indigo-html

An HTML abstraction layer.

1.0.0 2018-02-04 11:58 UTC

This package is auto-updated.

Last update: 2024-04-09 00:51:48 UTC


README

Indigo HTML tries to simplify HTML element manipulation. It does not work with DOMElement but provides an API of its own. It also provides integration with Zend View in the form of view helpers.

Installation

composer require hipnaba/indigo-html dev-master

Usage

<?php
// Creating elements
$link = new \Indigo\Html\Element\Element('a', [
    'class' => 'link',
]);

// Settings attributes
$link->setAttribute('href', '#');

// Working with css classes
$link->addClass('link-default');

// Setting content
$link->setContent('This is a link!');

// Nesting elements
$item = new \Indigo\Html\Element\Element('li');
$item->append($link);

$list = new \Indigo\Html\Element\Element('ul', [
    'id' => 'menu',
]);
$list->append($item);

// Rendering elements using the helper
echo $this->htmlElement($list);

The above example would render something like this:

<ul id="menu">
    <li>
        <a class="link link-default" href="#">This is a link!</a>
    </li>
</ul>