PHPackages                             maba/twig-template-modification-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. maba/twig-template-modification-bundle

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

maba/twig-template-modification-bundle
======================================

Bundle to Mass-Modify Twig Templates

1.0.1(9y ago)028451MITPHPPHP &gt;=5.3.2

Since Jun 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mariusbalcytis/twig-template-modification-bundle)[ Packagist](https://packagist.org/packages/maba/twig-template-modification-bundle)[ RSS](/packages/maba-twig-template-modification-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (1)

Bundle to Mass-Modify Twig Templates
====================================

[](#bundle-to-mass-modify-twig-templates)

What does this bundle do?
-------------------------

[](#what-does-this-bundle-do)

This bundle does not do anything by itself - it helps you to modify your existing twig templates by replacing parsed nodes with some other twig code.

It could be used to mass-edit many templates at once.

For usage example see [maba/webpack-migration-bundle](https://github.com/mariusbalcytis/webpack-migration-bundle).

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

[](#installation)

```
composer require maba/twig-template-modification-bundle
```

Inside `AppKernel`:

```
new Maba\Bundle\WebpackBundle\MabaTwigTemplateModificationBundle(),
```

Usage
-----

[](#usage)

Make service which implements `TwigNodeReplacerInterface`.

```
use Maba\Bundle\TwigTemplateModificationBundle\Service\TwigNodeReplacerInterface;
use Maba\Bundle\TwigTemplateModificationBundle\Entity\TemplateContext;
use Twig_Node as Node;

class MyNodeReplacer implements TwigNodeReplacerInterface
{
        /**
         * @param Node $node
         * @param TemplateContext $context
         *
         * @return null|string string if this node should be replaced with given twig code
         */
        public function replace(Node $node, TemplateContext $context)
        {
            if ($node instanceof NameExpression && $node->getAttribute('name') === 'my_var') {
                return '123';
            }
            return null;
        }
}
```

`replace` method will be called on each and every node in every twig template.

If string is returned (not `null`), node will be replaced with given string content.

`TemplateContext` holds template name. You can also add notices to it (for example unable to replace some node) and hold attributes (and reuse them later - same context is passed for each node in same template).

Initiate template rewrites with this code:

```
$factory = $container->get('maba_twig_template_modification.factory.files_replacer');
$replacer = $factory->createFilesReplacer(new MyNodeReplacer());

// both arguments (closures) are optional
$replacer->replace(function($filePath, $contents, $notices) {
    // log or write to output before replacing file in $filePath with $contents
}, function (array $notices) use ($output) {
    // log or write to output notices
});
```

You could also create replacer with dependency injection using factory service:

```

```

**Important!** Code replaces content in templates in your bundles and app directory - be sure to run it only when using version control system with no changes uncommitted.

Running tests
-------------

[](#running-tests)

[![Travis status](https://camo.githubusercontent.com/0dec6f538cd3e19cbf45585f9af5109c86a0293041908c9a0d5a64b641b8f99d/68747470733a2f2f7472617669732d63692e6f72672f6d617269757362616c63797469732f747769672d74656d706c6174652d6d6f64696669636174696f6e2d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mariusbalcytis/twig-template-modification-bundle)

```
composer install
vendor/bin/phpunit
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Total

2

Last Release

3619d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e131c9aa5f5a4fc3cc2f5e01b377ef33bbc3468acc95ff890fc6e8353d9cf67?d=identicon)[mariusbalcytis](/maintainers/mariusbalcytis)

---

Tags

twigtemplatesfind-replacemass-editmass-replacemass-modifymodification

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/maba-twig-template-modification-bundle/health.svg)

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M313](/packages/twig-extra-bundle)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

545.8M69](/packages/symfony-ux-icons)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

1432.0k](/packages/symfony-ux-toolkit)[yellowskies/qr-code-bundle

Symfony Barcode &amp; QR Code Generator Bundle with Twig extension

36682.9k](/packages/yellowskies-qr-code-bundle)[shoot/shoot

Shoot aims to make providing data to your templates more manageable

41229.9k2](/packages/shoot-shoot)[boekkooi/jquery-validation-bundle

Jquery form validation bundle for symfony 2

2773.9k1](/packages/boekkooi-jquery-validation-bundle)

PHPackages © 2026

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