PHPackages                             sanhpotter/html-compress-twig - 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. sanhpotter/html-compress-twig

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

sanhpotter/html-compress-twig
=============================

Twig extension for compressing HTML

09PHP

Since Jul 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sanhpotter/html-compress-twig)[ Packagist](https://packagist.org/packages/sanhpotter/html-compress-twig)[ RSS](/packages/sanhpotter-html-compress-twig/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

🗜 HtmlMin for Twig: HTML Compressor and Minifier
================================================

[](#-htmlmin-for-twig-html-compressor-and-minifier)

Description
-----------

[](#description)

A [Twig](http://twig.sensiolabs.org/) extension for [voku/HtmlMin](https://github.com/voku/HtmlMin).

Currently supported Twig features are:

- Tag

    - `{% htmlcompress %} bar {% endhtmlcompress %}`
- Function

    - `{{ htmlcompress(' bar') }}`
- Filter

    - `{{ ' bar' | htmlcompress }}`
- [Installation](#installation)
- [Usage](#usage)
- [History](#history)
- [License](#license)

Installation
------------

[](#installation)

1. Install and use [composer](https://getcomposer.org/doc/00-intro.md) in your project.
2. Require this package via composer:

```
composer require sn/html-compress-twig
```

Usage
-----

[](#usage)

First register the extension with Twig:

```
use voku\helper\HtmlMin;
use sn\twig\MinifyHtmlExtension;

$twig = new \Twig\Environment($loader);
$minifier = new HtmlMin();
$twig->addExtension(new MinifyHtmlExtension($minifier));
```

### Register extension in symfony 4

[](#register-extension-in-symfony-4)

Specifying HtmlMin is needed for the autowiring.

```
    voku\helper\HtmlMin:
        tags:
            - { name: HtmlMin }

    sn\twig\MinifyHtmlExtension:
        arguments:
            $forceCompression: false
        tags:
            - { name: twig.extension }
```

Then use it in your templates:

```
{% htmlcompress %} bar {% endhtmlcompress %}
{{ htmlcompress(' bar') }}
{{ ' bar' | htmlcompress }}

```

**Compression is disabled by Twig's `debug` setting.** This is to make development easier, however you can always override it.

The constructor of this extension takes a boolean as second parameter `$forceCompression`. When true, this will force compression regardless of Twig's `debug` setting. It defaults to false when omitted.

```
$twig->addExtension(new MinifyHtmlExtension($minifier, true));
```

History
-------

[](#history)

See [CHANGELOG](CHANGELOG.md) for the full history of changes.

License
-------

[](#license)

This project is licensed under the ISC license which is MIT/GPL compatible and FSF/OSI approved. See the [LICENSE](LICENSE) file for the full license text.

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e5717337c7c8e1edbf1637de6ecce85ceb243f35658db94f29ad707ce0ccc2e?d=identicon)[sanhpotter](/maintainers/sanhpotter)

### Embed Badge

![Health badge](/badges/sanhpotter-html-compress-twig/health.svg)

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

###  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)
