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 3w ago

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 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

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

906d 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

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[symfony/ux-twig-component

Twig components for Symfony

22018.6M352](/packages/symfony-ux-twig-component)[twig/markdown-extra

A Twig extension for Markdown

12116.2M130](/packages/twig-markdown-extra)[symfony/ux-live-component

Live components for Symfony

1647.0M127](/packages/symfony-ux-live-component)[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)
