PHPackages                             wipkip/html-object - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wipkip/html-object

ActiveLibrary

wipkip/html-object
==================

A set of classes to create and manipulate HTML objects abstractions, forked from Anahkiasen's html-object.

027PHP

Since Jun 4Pushed 12y ago1 watchersCompare

[ Source](https://github.com/rseyferth/html-object)[ Packagist](https://packagist.org/packages/wipkip/html-object)[ RSS](/packages/wipkip-html-object/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

HTMLObject
==========

[](#htmlobject)

HTMLObject is a set of classes to create and manipulate HTML objects abstractions.

Static calls to the classes
---------------------------

[](#static-calls-to-the-classes)

```
echo Element::p('text')->class('foobar');
// text
```

```
$list = List::ul(array('foo', 'bar'));

$link = Link::create('#', 'Someone');
$list->getChild(0)->addClass('active')->setValue('by '.$link);
//
//   foo
//   by Someone
//
```

```
echo Link::create('#foo', 'link')->class('btn btn-success')->blank();
// link
```

Extending the core classes
--------------------------

[](#extending-the-core-classes)

The core classes are meant to be extended and used to create complex patterns. All classes implement tree-crawling properties such as the following :

```
$element = Element::figure();

$element->nest('content') // content

$element->nest('p', 'content') // content

$image = Image::create('img.jpg')->alt('foo'); //
$element->setChild($image, 'thumb');

$element->getChild('thumb') // HtmlObject\Image
$element->nest(array(
  'caption' => Element::figcaption()->nest(array(
    'text' => Element::p('foobar'),
  )),
));

$element->getChild('caption.text')->getValue() // foobar
// OR
$element->captionText->getValue() // foobar
$element->captionText->getParent(0) // figure->caption
$element->captionText->getParent(1) // figure

$element->wrap('div') // ...
$element->wrapValue('div') // ...
```

You can see examples implementations in the [examples](examples) folder.

### Properties injection

[](#properties-injection)

If your class use properties that are at meant to be added to the final array of attributes, you can inject them using the `injectProperties` method. Say you have a `Link` class that has an `url` property, you can overwrite the method like this, and the `$this->url` will get added in the `href` attribute :

```
protected function injectProperties()
{
  return array(
    'href' => $this->url,
  );
}
```

Or if the property bears the property's name you can simply add it to the array of automatically injected properties :

```
protected $injectedProperties = array('href', 'title');

// Will be added as href="#foo"
protected $href = '#foo';

// Will be added as title="title"
protected $title = 'title';

```

### Altering a precreated tree

[](#altering-a-precreated-tree)

HtmlObject allows to use the `open` and `close` to open tags but when your tag has children you sometimes want to open the tree at a particular point to inject data at runtime, you can do it like this :

```
$mediaObject = Element::div([
  'title' => Element::h2('John Doe'),
  'body'  => Element::div(),
]);

echo $mediaObject->openOn('body').'My name is John Doe'.$mediaObject->close();
```

```

  John Doe
  My name is John Doe

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec43e0c18a8bbf40bf68ba48e5f85c6598ed0b516b2619f44ed33aafd77efaaa?d=identicon)[wipkip](/maintainers/wipkip)

---

Top Contributors

[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (76 commits)")[![rseyferth](https://avatars.githubusercontent.com/u/1991813?v=4)](https://github.com/rseyferth "rseyferth (5 commits)")

### Embed Badge

![Health badge](/badges/wipkip-html-object/health.svg)

```
[![Health](https://phpackages.com/badges/wipkip-html-object/health.svg)](https://phpackages.com/packages/wipkip-html-object)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
