PHPackages                             tentwofour/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. tentwofour/twig

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

tentwofour/twig
===============

Twig extensions

1.1.1(3y ago)03181MITPHPPHP ^7.0|^8.0CI failing

Since Sep 29Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tentwofour/twig)[ Packagist](https://packagist.org/packages/tentwofour/twig)[ Docs](https://github.com/tentwofour/twig)[ RSS](/packages/tentwofour-twig/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (5)Versions (7)Used By (1)

Twig
====

[](#twig)

A few Twig extensions

EmailEncodingExtension
----------------------

[](#emailencodingextension)

Provides a 'email\_encode' filter, that encodes text into a random mix of ascii, hex, and plain characters. Pulled from the SF1 libraries.

### email\_encode(&lt;string&gt; text)

[](#email_encodestring-text)

```
$ex = new EmailEncodingExtension()
$ex->filter('f@example.com');

// => &#x66;&#x40;&#101;&#120;a&#x6d;&#x70;&#108;&#101;&#x2e;&#x63;&#111;&#109;
```

```
{{ 'f@example.com'|email_encode }}
{# &#x66;&#x40;&#101;&#120;a&#x6d;&#x70;&#108;&#101;&#x2e;&#x63;&#111;&#109; #}
```

DiffExtension
-------------

[](#diffextension)

Provides 2 functions, 'diff', and 'diff\_html'.

### diff(&lt;iterable&gt; a, &lt;iterable&gt; b)

[](#diffiterable-a-iterable-b)

Differentiates 2 arrays, and returns a multi-dimensional array containing the differences.

```
$ex = new DiffExtension();

// Will also work with multi-dimensional arrays

$a = [
    'key' => 'value',
];
$b = [
    'key' => 'value_2',
];
$ex->diff($a, $b);

// => [
//            0 => [
//                'd' => [
//                    'key' => 'value',
//                ],
//                'i' => [
//                    'key' => 'value_2',
//                ],
//            ],
//        ]
```

```
{% set a = {'key': 'value'} %}
{% set b = {'key': 'value_2'} %}
{% set c = diff(a, b) %}
{#
{
    {
        'd': {
            'key': 'value'
        },
        'i': {
            'key': 'value_2'
        }
    }
}
#}
```

### diff\_html(&lt;string&gt; a, &lt;string&gt; b, &lt;string&gt; output)

[](#diff_htmlstring-a-string-b-string-output)

Differentiates 2 strings, and returns an array containing the differences, surrounded by HTML  and  tags.

Optionally returns a single string with the differences if *output* is set to 'string'.

```
$ex  = new DiffExtension();
$old = 'That&#39;s what it said on &quot;Ask Jeeves.&quot;';
$new = 'That&#39;s what it said on &quot;Dogpile.&quot;';

// Output to array
$ex->diffHtml($old, $new, 'array');

// => [
//            'old' => 'That&#39;s what it said on &quot;Ask Jeeves.&quot;',
//            'new' => 'That&#39;s what it said on &quot;Dogpile.&quot;',
//        ]

// Output to single string
$ex->diffHtml($old, $new, 'string');

// => 'That&#39;s what it said on &quot;Ask Jeeves.&quot;&quot;Dogpile.&quot;';
```

```
{{ diff_html('The lazy fox was eaten by the rabbid rabbit.', 'The stupid lazy fox was annihalited by the rabbit rabbit') }}

{# 'The stupidlazy fox was eatenannihilatedby the rabbid rabbit.rabbit rabbit' #}
```

InflectorExtension
------------------

[](#inflectorextension)

Provides string inflection functions: 'camelcase\_to\_capitalized\_words', 'camelcase\_to\_sentence\_case\_words', and 'camelcase\_to\_lower\_case\_words'.

```
$ex  = new InflectorExtension();
$string = 'camelCaseWordWith1Number';
$ex->camelCaseToCapitalizedWords($string)
// => 'Camel Case Word With 1 Number'
$ex->camelCaseToSentenceCasedWords($string)
// => 'Camel case word with 1 number'
$ex->camelCaseToLowerCasedWords($string)
// => 'camel case word with 1 number'
```

```
{{ 'camelCaseWordWith1Number'|camelcase_to_capitalized_words }}
{# 'Camel Case Word With 1 Number' #}

{{ 'camelCaseWordWith1Number'|camelcase_to_sentence_case_words}}
{# 'Camel case word with 1 number' #}

{{ 'camelCaseWordWith1Number'|camelcase_to_lower_case_words }}
{# 'camel case word with 1 number' #}
```

MoneyExtension
--------------

[](#moneyextension)

Provides a 'cents\_to\_dollars' filter; which does exactly what it says it does.

```
$ex = new MoneyExtension();
$ex->centsToDollars(1200);
// => '12.00'
```

```
{{ 1200|cents_to_dollars }}
{# '12.00' #}
```

NumberExtension
---------------

[](#numberextension)

Provides a 'number\_to\_human\_readable' filter, to round to the closest thousand or million, and add a suffix (K, M).

### number\_to\_human\_readable(&lt;int|float&gt; number, $precision, method)

[](#number_to_human_readableintfloat-number--precision--method)

```
$ex = new NumberExtension();
$ex->formatNumberToHumanReadable(1200000);
// => '1.2M'

$ex->formatNumberToHumanReadable(999.99);
// => '1K'

$ex->formatNumberToHumanReadable(3154.14159, 2, 'ceil');
// => 3.16K'

$ex->formatNumberToHumanReadable(3154.14159, 2, 'floor');
// => 3.15K
```

```
{{ 1200000|number_to_human_readable }}
{# '1.2M' #}
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity72

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

Recently: every ~609 days

Total

6

Last Release

1306d ago

PHP version history (6 changes)1.0.0PHP &gt;=5.3.3

1.0.1PHP &gt;=5.4

1.0.2PHP ~5.6|~7.0

1.0.3PHP ^5.6|^7.0

1.1.0PHP ^7.0

1.1.1PHP ^7.0|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4117615?v=4)[Blair D. Patterson](/maintainers/tentwofour)[@tentwofour](https://github.com/tentwofour)

---

Top Contributors

[![tentwofour](https://avatars.githubusercontent.com/u/4117615?v=4)](https://github.com/tentwofour "tentwofour (10 commits)")

---

Tags

twigten24tentwofour

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tentwofour-twig/health.svg)

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

###  Alternatives

[symfony/ux-twig-component

Twig components for Symfony

22018.6M356](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1647.0M127](/packages/symfony-ux-live-component)[shopware/storefront

Storefront for Shopware

684.6M235](/packages/shopware-storefront)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M572](/packages/shopware-core)[symfony/ux-toolkit

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

16126.1k1](/packages/symfony-ux-toolkit)[mati365/ckeditor5-symfony

CKEditor 5 integration for Symfony

262.6k](/packages/mati365-ckeditor5-symfony)

PHPackages © 2026

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