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

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

gubler/twig-extensions
======================

Twig extensions for internal projects

v1.1.0(2y ago)058MITPHPPHP ^8.1

Since Feb 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gubler/twig-extensions)[ Packagist](https://packagist.org/packages/gubler/twig-extensions)[ Docs](https://github.com/gubler/twig-extensions)[ RSS](/packages/gubler-twig-extensions/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

TwigExtensions
==============

[](#twigextensions)

This project provides several Twig extensions for internal projects.

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

[](#installation)

The preferred method of installation is via Composer. Run the following command to install the package and add it as a requirement to your project's `composer.json`:

```
composer require gubler/twig-extensions
```

### Configuration

[](#configuration)

```
$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new Gubler\Twig\Extension\FileIconClassExtension());
$twig->addExtension(new Gubler\Twig\Extension\FlashMessagesExtension());
$twig->addExtension(new Gubler\Twig\Extension\InstanceOfExtension());
$twig->addExtension(new Gubler\Twig\Extension\TableSortIconExtension());
```

For Symfony, register it in your `services.yaml`

```
services:
    gubler.twig_extension.file_icon_class:
        class: Gubler\Twig\Extension\FileIconClassExtension
        tags: [twig.extension]
    gubler.twig_extension.flash_messages:
        class: Gubler\Twig\Extension\FlashMessagesExtension
        tags: [twig.extension]
    gubler.twig_extension.instance_of:
        class: Gubler\Twig\Extension\InstanceOfExtension
        tags: [twig.extension]
    gubler.twig_extension.table_sort_icon:
        class: Gubler\Twig\Extension\TableSortIconExtension
        tags: [twig.extension]
```

You can also use the `MimeTypeToIconClass` library directly and inject it into your classes by registering it as a service:

```
services:
    Gubler\Twig\Extension\Lib\MimeTypeToIconClass: ~
```

Extensions
----------

[](#extensions)

### FileIconClass

[](#fileiconclass)

This maps a mimetype to a FontAwesome file icon. This currently only supports the following filetypes:

- MS Word
- MS Excel
- MS PowerPoint
- PDF

All other files return a generic file icon.

```
{{ 'application/vnd.ms-excel'|fileIconClass }}
```

### FlashMessages

[](#flashmessages)

This extension will iterate through the flashes of a given Session and convert them to Bootstrap 5 alerts.

This looks for the flash keys of `success`, `warning`, `error`, and `notice`.

Creating the flashes:

```
# In a Symfony controller:
$this->addFlash('success', 'This is a SUCCESS message');
$this->addFlash('error', 'This is an ERROR message');
$this->addFlash('warning', 'This is a WARNING message');
$this->addFlash('notice', 'This is a NOTICE message');
```

Rendering all flashes:

```
{{ flashMessages(app.session) }}
```

### InstanceOf

[](#instanceof)

This extension provides PHP's `instanceof` type operator as a Twig test.

```
{# date is \DateTime object #}
{{ date is instanceof("\\DateTime") ? 'ok' : 'bad' }}
```

### TableSortIcon

[](#tablesorticon)

This filter allows you to pass the column name, the sorted column name, and sort direction and get back a FontAwesome sorting icon classes.

```

```

Contributing
------------

[](#contributing)

Contributions are welcome! Please read [CONTRIBUTING](https://github.com/gubler/twig-extensions/blob/master/CONTRIBUTING.md) for details.

This project adheres to a [Contributor Code of Conduct](https://github.com/gubler/twig-extensions/blob/master/CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.

Copyright and License
---------------------

[](#copyright-and-license)

The gubler/twig-extensions library is copyright © [Daryl Gubler](http://dev88.co/) and licensed for use under the MIT License (MIT). Please see [LICENSE](https://github.com/gubler/twig-extensions/blob/master/LICENSE) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

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

Total

5

Last Release

852d ago

Major Versions

v0.2.0 → v1.0.02021-12-16

PHP version history (4 changes)v0.1.0PHP ^7.2.5

v0.2.0PHP ^7.2.5 || ^8.0

v1.0.0PHP ^8.0

v1.1.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![gubler](https://avatars.githubusercontent.com/u/3446?v=4)](https://github.com/gubler "gubler (9 commits)")

---

Tags

twightml

### Embed Badge

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

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

###  Alternatives

[twig/string-extra

A Twig extension for Symfony String

21946.0M132](/packages/twig-string-extra)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)[twig/html-extra

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)[twig/cache-extra

A Twig extension for Symfony Cache

392.1M20](/packages/twig-cache-extra)[spress/spress

Static site generator with blogs support

37436.2k](/packages/spress-spress)[nochso/html-compress-twig

Twig extension for compressing HTML and inline CSS/Javascript

84468.6k7](/packages/nochso-html-compress-twig)

PHPackages © 2026

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