PHPackages                             phpmob/twig-modify-bundle - 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. phpmob/twig-modify-bundle

ActiveSymfony-bundle[Templating &amp; Views](/categories/templating)

phpmob/twig-modify-bundle
=========================

Twig Minifier just you like.

2.0.0(8y ago)25.5k1MITPHPPHP ^5.6|^7.0

Since Aug 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/phpmob/twig-modify-bundle)[ Packagist](https://packagist.org/packages/phpmob/twig-modify-bundle)[ Docs](http://github.com/phpmob/twig-modify-bundle)[ RSS](/packages/phpmob-twig-modify-bundle/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (6)Dependencies (9)Versions (7)Used By (1)

TwigModifyBundle
================

[](#twigmodifybundle)

TwigModify is a twig tag that can modifies everythink you want eg. `cssmin`, `jsmin` and more.

Installing
----------

[](#installing)

Installing via `composer` is recommended.

```
"require": {
  "phpmob/twig-modify-bundle": "~2.0"
}
```

Enabling
--------

[](#enabling)

And then enable bundle in `AppKernel.php`

```
public function registerBundles()
{
    $bundles = [
        ...
        new \PhpMob\TwigModifyBundle\PhpMobTwigModifyBundle(),
    ];
}
```

Usage
-----

[](#usage)

In order to modify your twig is simple just wrap `{% modify modifier %}...{% modify %}` like this:

```
{% modify jsmin %}

        $(function() {
                ....
        });

{% endmodify %}
```

That was it!

Build-in Modifiers
------------------

[](#build-in-modifiers)

There are supported modifiers in this bundle.

#### JSMin

[](#jsmin)

A wrapped modifier for `\JShrink\Minifier::minify`, Thanks [tedivm/jshrink](https://github.com/tedious/JShrink)

```
{% modify jsmin %}

        $(function() {
                ....
        });

{% endmodify %}
```

#### CSSMin

[](#cssmin)

A wrapped modifier for `\tubalmartin\CssMin\Minifier::minify`, Thanks [tubalmartin/cssmin](https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port)

```
{% modify cssmin %}

        body {
            color: red;
        }

{% endmodify %}
```

#### HtmlPurify

[](#htmlpurify)

A wrapped modifier for `\HTMLPurifier::purify`, Thanks [ezyang/htmlpurifier](https://github.com/ezyang/htmlpurifier)

```
{% modify htmlpurify %}

{% endmodify %}
```

#### AntiXss

[](#antixss)

A wrapped modifier for `\voku\helper\AntiXSS`, Thanks [voku/anti-xss](https://github.com/voku/anti-xss)

```
{% modify antixss %}
    {{ harm_string|raw }}
{% endmodify %}
```

Cache
-----

[](#cache)

TwigModifyBundle use local cache folder by default, however you can use any cache that implemented `\Symfony\Component\Cache\Adapter\AdapterInterface` interface and then change the confiuration for your cache service:

```
phpmob_twig_modify:
    cache_adapter: "my_cache_adapter_service_id"
```

You can also use symfony [framework-bundle cache adapter](https://symfony.com/doc/current/reference/configuration/framework.html#reference-templating-cache).

```
phpmob_twig_modify:
    cache_adapter: "cache.app"
```

Don't fogot enable `DoctrineCacheBundle` in your `AppKernel.php` - See

Your own modifiers
------------------

[](#your-own-modifiers)

You can add/override modifiers by easy configuration:

```
phpmob_twig_modify:
    modifiers:
        xss: # a modifier name
            enabled: true # default true, toggle enable/disable this modifier.
            class: \PhpMob\TwigModifyBundle\Modifier\HTMLPurify # static class or any service
            method: purify # service method that's allowed to accept `[$content, (array) $options]
            options: # are array options you want to past into your modifier method - `\PhpMob\TwigModifyBundle\Modifier\HTMLPurify::purify` in this case.
                Cache.SerializerPath: "%kernel.cache_dir%/htmlpurify"
```

After that you already to use your new modifier.

```
 {% modify xss %}

 {% endmodify %}
```

Configuration
-------------

[](#configuration)

Configuration reference:

```
phpmob_twig_modify:
    # cache adapter serivce implemented `\Symfony\Component\Cache\Adapter\AdapterInterface` interface.
    cache_adapter: "my_cache_service_id"
    # application wide toggle enable/disable all modifiers
    enabled: true
    # custom/override modifiers (same key of modifier will override other previous defined)
    modifiers:
        name:
            class: ModifierClassOrService
            method: ModifierMethod
            options: ArrayOfSecondModifierMethod
            enabled: ToggleDisableEnable
```

Thanks
------

[](#thanks)

```
- https://github.com/nibsirahsieu/SalvaJshrinkBundle to nice demonstration.
- https://github.com/Exercise/HTMLPurifierBundle to nice demonstration.
- https://github.com/ezyang/htmlpurifier
- https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
- https://github.com/tedious/JShrink
- https://github.com/voku/anti-xss

```

License
-------

[](#license)

[MIT](/LICENSE)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

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

Recently: every ~30 days

Total

6

Last Release

3111d ago

Major Versions

1.1.3 → 2.0.02017-12-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/c47688f793047a866ae4742e5ead45fff7a47910e89cd9997c28315605a5d888?d=identicon)[liverbool](/maintainers/liverbool)

---

Top Contributors

[![liverbool](https://avatars.githubusercontent.com/u/206804?v=4)](https://github.com/liverbool "liverbool (13 commits)")

---

Tags

cssminhtmlpurifyjsminminifiertwigjavascriptcsshtmlminifiercssminxssjsminhtmlpurify

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpmob-twig-modify-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/phpmob-twig-modify-bundle/health.svg)](https://phpackages.com/packages/phpmob-twig-modify-bundle)
```

###  Alternatives

[chameleon-system/chameleon-base

The Chameleon System core.

1027.9k4](/packages/chameleon-system-chameleon-base)

PHPackages © 2026

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