PHPackages                             natepage/easy-html-element - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. natepage/easy-html-element

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

natepage/easy-html-element
==========================

An easy way to create simple or complex html elements in PHP.

v1.2.0(9y ago)524MITPHPPHP ^7.0

Since Jan 21Pushed 9y ago2 watchersCompare

[ Source](https://github.com/natepage/easy-html-element)[ Packagist](https://packagist.org/packages/natepage/easy-html-element)[ Docs](https://github.com/natepage/easy-html-element)[ RSS](/packages/natepage-easy-html-element/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

EasyHtmlElement
===============

[](#easyhtmlelement)

 [![Build Status](https://camo.githubusercontent.com/18f1a5d788524916a425fa9db09c45fc93a876c8f78b92cee170e29f46434866/68747470733a2f2f7472617669732d63692e6f72672f6e617465706167652f656173792d68746d6c2d656c656d656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/natepage/easy-html-element) [![SensioLabs Insight](https://camo.githubusercontent.com/2ff18f3f4bf561f252b1184d401d91556e2b54eb7b53e4bafeb2062d78186262/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f31636133376430382d363838392d343238302d616134632d3537333962663262653438612e737667)](https://insight.sensiolabs.com/projects/1ca37d08-6889-4280-aa4c-5739bf2be48a) [![Quality Score](https://camo.githubusercontent.com/063a29634f4379876f47e89108ca58b35833f0476c9e5e21448eba7d19122367/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6e617465706167652f656173792d68746d6c2d656c656d656e742e737667)](https://scrutinizer-ci.com/g/natepage/easy-html-element)

An easy way to create simple or complex html elements in PHP.

---

**EasyHtmlElement** is an open source software library which allows you to define a map of your html elements and use them simply in your html code. You can define simple elements like links, buttons, lists, images or use custom types. But the power of this library is to define complex html structures with elements which has attributes, parent, children or extends others elements attributes. And after your elements map made, you can do it with only one PHP method!

\##Installation ####Composer Find all informations about Composer from `https://getcomposer.org/`

Run the following command:

```
$ composer require natepage/easy-html-element

```

\####Repository You can directly clone the repository but you'll have to install the dependencies manually.

\##Usage Did you already use an array in PHP? Yes? Nice! With EasyHtmlElement just have to create a simple PHP array and we manage the rest! We'll call this array *map* for all the next examples.

So *map* is a simple key/value array where you will define your html elements like:

- key (string): The element name you'll use to generate it in your code
- value (array): All the element informations

\####Simple example

```
$map = array(
    'myDiv' => array(
        'type' => 'div',
        'text' => 'Simple Div Example'
    )
);

$htmlElement = new NatePage\EasyHtmlElement\HtmlElement();
$div = $htmlElement->load('myDiv');

echo $div;

/**
 *
 *      Simple Div Example
 *
 */
```

In the example above we just display a simple div and yes I agree you don't really need a library to do that but it's to show the logic so if you want to see the real power of EasyHtmlElement keep reading!

You can see you don't need to call a specific method to render elements, we use the magic method \_\_*toString()* to make your life easier! :)

\####More Complex Example (Bootstrap Panel)

```
$map = array(
    //Base div
    'div' => array(
        'type' => 'div'
    ),
    //Base panel structure
    'panel' => array(
        'extends' => array('div'),
        'attr' => array('class' => 'panel'),
        'children' => array(
            'panelHeading',
            'panelBody',
            'panelFooter'
        )
    ),
    //Panel heading
    'panelHeading' => array(
        'extends' => array('div'),
        'attr' => array('class' => 'panel-heading'),
        'children' => array(
            array(
                'name' => 'panelHeadingTitle',
                'type' => 'h3',
                'attr' => array('class' => 'panel-title'),
                'text' => '%panel_title%'
            )
        )
    ),
    //Panel body
    'panelBody' => array(
        'extends' => array('div'),
        'attr' => array('class' => 'panel-body'),
        'text' => '%panel_body%'
    ),
    //Panel footer
    'panelFooter' => array(
        'extends' => array('div'),
        'attr' => array('class' => 'panel-footer'),
        'text' => '%panel_footer%'
    ),
    //Primary panel structure
    'panelPrimary' => array(
        'extends' => array('panel'),
        'attr' => array('class' => 'panel-primary')
    )
);

$htmlElement = new \NatePage\EasyHtmlElement\HtmlElement($map);
$panelPrimary = $htmlElement->load('panelPrimary', null, array(), array(
    'panel_title' => 'My Panel Title',
    'panel_body' => 'My Panel Body',
    'panel_footer' => 'My Panel Footer'
));

echo $panelPrimary;

/**
 *
 *
 *          My Panel Title
 *
 *
 *          My Panel Body
 *
 *
 *          My Panel Footer
 *
 *
 */
```

Here we have:

- All the panel components extend the *Base div* element to get the *div* type
- Base panel structure define *children* to make its content
- All elements define their own attributes with *attr*
- Panel heading defines a dynamic child directly in its children array
- Primary panel structure extends all the Base panel structure and add a css class
- Some parameters with the *%parameter%* syntax which allows you to define dynamic content

A complex and dynamic html structure in just on method, that's what EasyHtmlElement promised you!

\##Integrations EasyHtmlElement provides integrations for:

- Symfony
- Twig
- Laravel

More informations from [integrations](doc/integrations.md).

\##Documentation Does it make you want to learn more about the EasyHtmlElement power?

Read the [documentation](doc/index.md).

\##Dependencies

- [airmanbzh/php-html-generator](https://github.com/Airmanbzh/php-html-generator) to render html elements
- [zendframework/zend-escaper](https://github.com/zendframework/zend-escaper) to secure the generated html code with escaping strategies

We actively recommend you to use [symfony/yaml](http://symfony.com/doc/current/components/yaml.html) to make your map building easier.

\##Customization If you need to customize the code logic, EasyHtmlElement one more time makes it easier for you with somes interfaces. All informations in the [documentation](doc/customization.md).

\##Contributing Please don't hesitate to open an issues or a pull request if you find something wrong in the code, a typo in the documentation, if you have an evolution idea in mind or if you just want to say hello! :)

\##Versioning EasyHtmlElement is maintained under the Semantic Versioning guidelines so releases will be numbered with the following format:

```
MAJOR.MINOR.PATCH

```

For more informations on SemVer, please visit `http://semver.org`

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 97.6% 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 ~2 days

Total

4

Last Release

3439d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6

v1.1.0PHP ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11576446?v=4)[Nathan Page](/maintainers/natepage)[@natepage](https://github.com/natepage)

---

Top Contributors

[![natepage](https://avatars.githubusercontent.com/u/11576446?v=4)](https://github.com/natepage "natepage (41 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

composerhtml-elementphp

### Embed Badge

![Health badge](/badges/natepage-easy-html-element/health.svg)

```
[![Health](https://phpackages.com/badges/natepage-easy-html-element/health.svg)](https://phpackages.com/packages/natepage-easy-html-element)
```

###  Alternatives

[cronkeep/cronkeep

Web-based crontab manager

2872.8k](/packages/cronkeep-cronkeep)[deltasystems/dewdrop

121.0k](/packages/deltasystems-dewdrop)

PHPackages © 2026

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