PHPackages                             jesspinkman/pure - 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. jesspinkman/pure

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

jesspinkman/pure
================

Create HTML Markups without HTML code, easily nest elements and set attributes

3.0.4(4y ago)131551MITPHPPHP ^8.0

Since Sep 7Pushed 2y ago2 watchersCompare

[ Source](https://github.com/JessPinkman/Pure)[ Packagist](https://packagist.org/packages/jesspinkman/pure)[ RSS](/packages/jesspinkman-pure/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (42)Used By (1)

Pure
====

[](#pure)

Library to create, use and reuse components to generate html.

- Combine elements freely and seamlessly.
- Easily add attributes to any element with the use of magic \_\_call.
- Create complexe structures that you can interact with by extending the class.
- Makes your code very clean and readable.

**Also check [BSPure](https://github.com/JessPinkman/BSPure), an extension to use Bootstrap components.**

How
===

[](#how)

There are two main classes:

Pure\\Component
---------------

[](#purecomponent)

```
This is the class that abstracts an html markup element
you combine them to create your html
use magic calls to define the markup attributes

```

Pure\\Pure
----------

[](#purepure)

```
This is the factory, use static magic calls to create components.
You can then chain magic calls on the component to create the component attributes

```

### example:

[](#example)

```
use Pure\Pure;

echo Pure::h3()
    ->id('my-first-pure-component')
    ->class('badge badge-primary')
    ->my_custom_prop('pure')
    ->___('Hello World!');
```

###### output

[](#output)

```

  Hello World!

```

### Nesting:

[](#nesting)

```
echo Pure::div()
    ->class('container')
    ->___(
        Pure::p()
            ->class('inner')
            ->___("I'm nested !")
    );
```

###### output

[](#output-1)

```

  I'm nested !

```

### Extend the Component class to create reusable components in your projects

[](#extend-the-component-class-to-create-reusable-components-in-your-projects)

```
use Pure\Component;
use Pure\Pure;

//Create a select component, to spped up its creation
//Some magic to add the name attribute, as well as class for children

class Select extends Component {

    function __construct( string $name, ...$children )
    {
        parent::__construct( 'select' );    //create component with 'select' markup
        $this
            ->class('form__select')         //add class attribute = 'form__select'
            ->name( $name )                 //assign attribute name with passed $name in constructor
            ->___($children);            //append children
    }
}

class Option extends Component
{

    public function __construct( string $label, $value = null, bool $disabled = false )
    {
        parent::__construct('option');      //create component with 'option' markup
        $this
            ->class('form__option')         //add class attribute = 'form__option'
            ->value($value ?? false)        //add value attribute if it is defined, otherwise no value attribute
            ->disabled($disabled)           //add disabled attribute if necessary
            ->___($label);               //append label inside in inner html
    }
}

echo Pure::form()
    ->id('select-form')
    ->___(
        new Select('user-preference', [
            new Option( 'Select your preference', null, true ),
            new Option( 'A is the best', 'a' ),
            new Option( 'B is better', 'b' ),
            new Option( 'C is amazing', 'c' )
        ]);
    );
```

###### output

[](#output-2)

```

    Select your preference
    A is the best
    B is better
    C is amazing

```

### Advanced example

[](#advanced-example)

let's create different reusable components (views)

- default Page view
- grid view
- product view

```
//default page view, already includes head, header and footer views, we just need to pass the main content
class DefaultPageView extends Component
{
    public function __construct(...$inner_content)
    {
        parent::__construct('html');
        $this->___(
            new PageHead(),
            Pure::body(
                new HeaderView(),
                Pure::main($inner_content),
                new FooterView()
            )
        );
    }

    // Overwrite __toString in order to include doctype at beginning of the page
    public function __toString(): string
    {
        return '' . parent::__toString();
    }
}

//reusable component to create an html grid, and assign a class to all grid children
class GridView extends Component
{
    public function __construct(...$tiles)
    {
        parent::__construct('div');
        $this
            ->id('grid')
            ->___($tiles);
    }

    //overwrite ___ method in order to abstract a grid specific structure, each child is a div with a specific class
    public function ___(...$children): self
    {
        foreach ($children as $child) {
            parent::___(
                Pure::div()
                    ->class('grid_child')
                    ->___($child)
            );
        }
    }
}

//reusable component to render a single product tile html
class ProductView extends Component
{

    public function __construct(array $product)
    {
        parent::__construct('article');             // create component with article markup
        $this
            ->class('product__tile')                //add class
            ->data_product_id($product['id'])       //add custom attribute
            ->___(
                Pure::h1()                          //first child, the title
                    ->class('product__tile_title')
                    ->___($product['name']),
                Pure::img()                         //second child, the image
                    ->class('product__tile_img')
                    ->src($product['imgURL'])
                    ->alt($product['name']),
                Pure::span()                        //third child, the price
                    ->class('product__tile_price tag')
                    ->class($product['promotion'] ? 'product__tile_price--promotion' : 'product__tile_price--no-promotion') //conditionally load class
                    ->___("USD $product->price"),
            );
    }
}

//to use inside your view controller
$products = Product::getProductList();
$product_views = array_map(fn ($single) => new ProductView($single), $products);

echo new DefaultPageView(new GridView($product_views));
```

###### output

[](#output-3)

```
>

    ...

    ...

            Blue Sweater

              USD 39

            Red Dress

              USD 59

            Grey Fedora

              USD 40

    ...

```

And build from here even more complexe structures...

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~6 days

Recently: every ~0 days

Total

40

Last Release

1811d ago

Major Versions

1.3.1 → 2.0.02020-09-13

2.2.4 → 3.0.02021-05-26

PHP version history (4 changes)1.0.0-alpha1PHP ^7.2

2.2.1PHP ^7.4

2.2.2PHP ^7.4 | ^8.0

3.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34494151?v=4)[jesspinkman](/maintainers/jesspinkman)[@JessPinkman](https://github.com/JessPinkman)

---

Top Contributors

[![JessPinkman](https://avatars.githubusercontent.com/u/34494151?v=4)](https://github.com/JessPinkman "JessPinkman (66 commits)")

### Embed Badge

![Health badge](/badges/jesspinkman-pure/health.svg)

```
[![Health](https://phpackages.com/badges/jesspinkman-pure/health.svg)](https://phpackages.com/packages/jesspinkman-pure)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[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)

PHPackages © 2026

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