PHPackages                             ocubom/twig-html-extension - 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. ocubom/twig-html-extension

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

ocubom/twig-html-extension
==========================

A custom suite of Twig filters for HTML manipulation

v2.1.0(2y ago)12.6k2MITPHPPHP &gt;=7.4

Since Aug 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ocubom/twig-html-extension)[ Packagist](https://packagist.org/packages/ocubom/twig-html-extension)[ Docs](https://github.com/ocubom/twig-html-extension)[ RSS](/packages/ocubom-twig-html-extension/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (4)Versions (6)Used By (2)

Ocubom Twig HTML Extension
==========================

[](#ocubom-twig-html-extension)

A custom suite of Twig filters for HTML manipulation

[![Contributors](https://camo.githubusercontent.com/7689741491775ebea02c800885b8c1ab7cbaff638e55973b6c3b47b0ea9cb6f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/twig-html-extension/graphs/contributors)[![Forks](https://camo.githubusercontent.com/01141d606f8ba80bf97a26d3b4e84fed2b5ef8702f18eeaebb806e74b9c95e96/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/twig-html-extension/network/members)[![Stargazers](https://camo.githubusercontent.com/54897fc26fd56d2f06524e455bc59db40abb2909317c0f09713cb533f4aff03a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/twig-html-extension/stargazers)[![Issues](https://camo.githubusercontent.com/5c40ada024404c7d513f7107cb0a0cec2493cedf36d40deed01b7303162cff44/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/twig-html-extension/issues)[![License](https://camo.githubusercontent.com/217d73996c15af09e8149358e9908f90a78046e8b37026f65929afb095626163/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/twig-html-extension/blob/master/LICENSE)

[![Version](https://camo.githubusercontent.com/f75d15a4f7239a1d6b6a738972163922909ecc09dae31ba4b1b929ed5a5cbf95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d253233666566656665267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/ocubom/twig-html-extension)[![CI](https://camo.githubusercontent.com/2152c0c1e53d8510e6fdaa01727a241465891fa607baaaa8a3c532b4987535af/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349266c6f676f3d676974687562267374796c653d666f722d7468652d6261646765)](https://github.com/ocubom/twig-html-extension/actions/)[![Code Quality](https://camo.githubusercontent.com/147b23c813c0b6b3dce617c46886801f92c3a6c14b31ab36affa17ce57915c2c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f6c6f676f3d7363727574696e697a6572266c6f676f436f6c6f723d666666267374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/ocubom/twig-html-extension/)[![Coverage](https://camo.githubusercontent.com/45e948b9542e0f0fd6661028246685aebb1ee6ab8d04ecc2450eb3deb3ac7a43/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6f6375626f6d2f747769672d68746d6c2d657874656e73696f6e2e7376673f6c6f676f3d7363727574696e697a6572266c6f676f436f6c6f723d666666267374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/ocubom/twig-html-extension/code-structure/main/code-coverage)

[**Explore the docs »**](https://github.com/ocubom/twig-html-extension)

[Report Bug](https://github.com/ocubom/twig-html-extension/issues)· [Request Feature](https://github.com/ocubom/twig-html-extension/issues)

Contents- [About TwigHtmlExtension](#about-twightmlextension)
- [Getting Started](#getting-started)
    - [Installation](#installation)
    - [Usage](#usage)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [Authorship](#authorship)
- [License](#license)

About TwigHtmlExtension
-----------------------

[](#about-twightmlextension)

[TwigHtmlExtension](https://github.com/ocubom/twig-html-extension) is a custom suite of **[Twig filters](https://twig.symfony.com/doc/3.x/advanced.html#filters)** for HTML manipulation.

This suite started as an internal class based on [nochso/html-compress-twig](https://packagist.org/packages/nochso/html-compress-twig) to allow the use of [wyrihaximus/html-compress](https://packagist.org/packages/wyrihaximus/html-compress) with Twig 3.0. This class used to be embedded into several projects. Over time, each project adapted its version slightly, leading to fragmented development and difficult maintenance. Therefore, the development is unified in this extension which is made public in case it is useful for other projects.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

Just use [composer](https://getcomposer.org/) to add the dependency:

```
composer require ocubom/twig-html-extension
```

Or add the dependency manually:

1. Update `composer.json` file with the lines:

    ```
    {
        "require": {
            "ocubom/twig-html-extension": "^1.0.0"
        }
    }
    ```
2. And update the dependencies:

    ```
    composer update "ocubom/twig-html-extension"
    ```

### Usage

[](#usage)

Just register the Twig extension:

```
$twig = new \Twig\Environment();
$twig->addExtension(new \Ocubom\Twig\Extension\HtmlExtension());
$thig->addRuntimeLoader(use Twig\RuntimeLoader\FactoryRuntimeLoader([
    \Ocubom\Twig\Extension\HtmlAttributesRuntime::class => function() {
        return new \Ocubom\Twig\Extension\HtmlAttributesRuntime();
    },
    \Ocubom\Twig\Extension\HtmlCompressRuntime::class => function() {
        return new \Ocubom\Twig\Extension\HtmlCompressRuntime();
    },
]));

// You can also dynamically create a RuntimeLoader
$twig->addRuntimeLoader(new class() implements RuntimeLoaderInterface {
    public function load($class)
    {
        if (\Ocubom\Twig\Extension\HtmlAttributesRuntime::class === $class) {
            return new \Ocubom\Twig\Extension\HtmlAttributesRuntime();
        }

        if (\Ocubom\Twig\Extension\HtmlCompressRuntime::class === $class) {
            return new \Ocubom\Twig\Extension\HtmlCompressRuntime();
        }

        return null;
    }
});
```

*For more examples, please refer to the [Documentation](https://github.com/ocubom/twig-html-extension).*

Roadmap
-------

[](#roadmap)

See the [open issues](https://github.com/ocubom/twig-html-extension/issues) for a full list of proposed features (and known issues).

Contributing
------------

[](#contributing)

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

1. Fork the Project.
2. Create your Feature Branch (`git checkout -b feature/your-feature`).
3. Commit your Changes (`git commit -m 'Add your-feature'`).
4. Push to the Branch (`git push origin feature/your-feature`).
5. Open a Pull Request.

Authorship
----------

[](#authorship)

- Oscar Cubo Medina —

See also the list of [contributors](https://github.com/ocubom/twig-html-extension/graphs/contributors) who participated in this project.

License
-------

[](#license)

Distributed under the MIT License. See [LICENSE](https://github.com/ocubom/twig-html-extension/blob/master/LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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 ~117 days

Total

5

Last Release

885d ago

Major Versions

v1.0.2 → v2.0.02022-12-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/642ac779b1c36bfa6dfae27c756efcf88f75ff34fd50b376a72acb05e845502d?d=identicon)[ocubom](/maintainers/ocubom)

---

Top Contributors

[![ocubom](https://avatars.githubusercontent.com/u/184187?v=4)](https://github.com/ocubom "ocubom (20 commits)")

---

Tags

compresshtmlminifytwigtwig-extensiontwightmlminifycompresstwig-extension

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/ocubom-twig-html-extension/health.svg)

```
[![Health](https://phpackages.com/badges/ocubom-twig-html-extension/health.svg)](https://phpackages.com/packages/ocubom-twig-html-extension)
```

###  Alternatives

[nochso/html-compress-twig

Twig extension for compressing HTML and inline CSS/Javascript

84468.6k7](/packages/nochso-html-compress-twig)[twig/string-extra

A Twig extension for Symfony String

21946.0M132](/packages/twig-string-extra)[voku/html-compress-twig

Twig extension for compressing HTML

252.3M](/packages/voku-html-compress-twig)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[twig/html-extra

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)[fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

414211.4k](/packages/fitztrev-laravel-html-minify)

PHPackages © 2026

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