PHPackages                             anahkiasen/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. [Templating &amp; Views](/categories/templating)
4. /
5. anahkiasen/html-object

ActiveLibrary[Templating &amp; Views](/categories/templating)

anahkiasen/html-object
======================

A set of classes to create and manipulate HTML objects abstractions

1.4.4(8y ago)1311.6M↓34.8%21[2 PRs](https://github.com/Anahkiasen/html-object/pulls)17MITPHPPHP &gt;=5.3.0

Since Jun 6Pushed 3y ago3 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (12)Used By (17)

HTMLObject
==========

[](#htmlobject)

[![Build Status](https://camo.githubusercontent.com/fea8fe1dd77861339fb6f8ecb7c733df526c8e022599df3a89e0232e55f43d71/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f416e61686b696173656e2f68746d6c2d6f626a6563742e7376673f7374796c653d666c6174)](https://travis-ci.org/Anahkiasen/html-object)[![Latest Stable Version](https://camo.githubusercontent.com/92109bb70c2ad6e7f8145357aacfb4cfa6e5572c594a33b10f41378efb2cfb0b/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e61686b696173656e2f68746d6c2d6f626a6563742e7376673f7374796c653d666c6174)](https://packagist.org/packages/anahkiasen/html-object)[![Total Downloads](https://camo.githubusercontent.com/4552083afa24dbb2ddfa7d3f6df96607ffa36378ef47deb17817a330fc1c56dd/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e61686b696173656e2f68746d6c2d6f626a6563742e7376673f7374796c653d666c6174)](https://packagist.org/packages/anahkiasen/html-object)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/06b2511755650c3e620a47605012d334651bf61888f660954d3ead5d669ebd01/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f416e61686b696173656e2f68746d6c2d6f626a6563742e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/Anahkiasen/html-object/)[![Code Coverage](https://camo.githubusercontent.com/9fe9e1eb9226c03e940c208f7f6a8fe40368afdf2d17e4be6708a29ceb7cdeb7/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f416e61686b696173656e2f68746d6c2d6f626a6563742e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/Anahkiasen/html-object/)[![Support via Gittip](https://camo.githubusercontent.com/2700a79f496bdf434db90ac70e5e44e4b01905a98d59b74c66e7d24fcdb2e7c4/687474703a2f2f696d672e736869656c64732e696f2f6769747469702f416e61686b696173656e2e7376673f7374796c653d666c6174)](https://www.gittip.com/Anahkiasen/)

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

```

### Configuration

[](#configuration)

You can change whether to follow xHMTL or HTML5 specification by doing the following :

```
Tag::$config['doctype'] = '{xhtml|html}';
```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity55

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 92.2% 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.

###  Release Activity

Cadence

Every ~145 days

Recently: every ~305 days

Total

11

Last Release

3274d ago

Major Versions

0.1.0 → 1.1.02013-11-05

### Community

Maintainers

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

---

Top Contributors

[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (130 commits)")[![armandomiani](https://avatars.githubusercontent.com/u/512214?v=4)](https://github.com/armandomiani "armandomiani (2 commits)")[![patrickcarlohickman](https://avatars.githubusercontent.com/u/6036266?v=4)](https://github.com/patrickcarlohickman "patrickcarlohickman (2 commits)")[![mlocati](https://avatars.githubusercontent.com/u/928116?v=4)](https://github.com/mlocati "mlocati (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (1 commits)")[![weotch](https://avatars.githubusercontent.com/u/77567?v=4)](https://github.com/weotch "weotch (1 commits)")[![claar](https://avatars.githubusercontent.com/u/402855?v=4)](https://github.com/claar "claar (1 commits)")[![CWSpear](https://avatars.githubusercontent.com/u/495855?v=4)](https://github.com/CWSpear "CWSpear (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

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