ocubom/twig-html-extension

A custom suite of Twig filters for HTML manipulation

Maintainers

Package info

github.com/ocubom/twig-html-extension

pkg:composer/ocubom/twig-html-extension

Transparency log

Statistics

Installs: 2 641

Dependents: 2

Suggesters: 0

Stars: 1

Open Issues: 0

v2.2.0 2026-09-01 12:12 UTC

This package is auto-updated.

Last update: 2026-09-01 12:33:48 UTC


README

ocubom/twig-html-extension

A custom suite of Twig filters for HTML manipulation

Version PHP version License Build status Coverage

Downloads Issues Stargazers Forks Contributors

Explore the docs » · Report Bug · Request Feature

Table of Contents

About ocubom/twig-html-extension

ocubom/twig-html-extension is a custom suite of Twig extensions for HTML manipulation.

This suite started as an internal helper based on nochso/html-compress-twig to bring wyrihaximus/html-compress support to Twig 3.0. Over time, as several projects embedded and modified this class independently, development became fragmented and difficult to maintain. This repository unifies those efforts into a single, open-source package.

Starting in version 2.2.0, the engine was upgraded to directly use voku/html-min, replacing the legacy compressor dependencies. Full backward compatibility is maintained for legacy HtmlCompressRuntime.

Getting Started

Prerequisites

  • PHP >= 7.4 (tested up to 8.5)
  • Composer >= 2.0

Installation

Install the package via composer:

composer require ocubom/twig-html-extension

Usage

Register the extension and runtime loaders in your Twig environment:

use Twig\Environment;
use Twig\RuntimeLoader\FactoryRuntimeLoader;
use Ocubom\Twig\Extension\HtmlExtension;
use Ocubom\Twig\Extension\HtmlAttributesRuntime;
use Ocubom\Twig\Extension\HtmlMinifyRuntime;

$twig = new Environment($loader);

// Register the extension
$twig->addExtension(new HtmlExtension());

// Register runtime loaders
$twig->addRuntimeLoader(new FactoryRuntimeLoader([
    HtmlAttributesRuntime::class => fn() => new HtmlAttributesRuntime(),
    HtmlMinifyRuntime::class => fn() => new HtmlMinifyRuntime(),
]));

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

Roadmap

See the open issues for a list of proposed features (and known issues).

Support

Reach out to the maintainer at GitHub Issues.

Authorship

Oscar Cubo Medinahttps://ocubom.github.io

For a full list of all authors and contributors, see the contributors page.

License

Distributed under the MIT License.

See LICENSE for more information.