PHPackages                             gglnx/twig-empty-coalesce - 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. gglnx/twig-empty-coalesce

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

gglnx/twig-empty-coalesce
=========================

The empty test and default filter as an operator

1.0.1(4y ago)06.8k↓29.2%MITPHPPHP &gt;=7.2.5

Since Jan 5Pushed 4y ago1 watchersCompare

[ Source](https://github.com/gglnx/twig-empty-coalesce)[ Packagist](https://packagist.org/packages/gglnx/twig-empty-coalesce)[ RSS](/packages/gglnx-twig-empty-coalesce/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Empty Coalesce Operator for Twig
================================

[](#empty-coalesce-operator-for-twig)

[![Packagist](https://camo.githubusercontent.com/ce8ebff4981efb1c45b6c2a5c393a129f866f3a0e11f6ada9c136577734dbb51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67676c6e782f747769672d656d7074792d636f616c657363652e737667)](https://packagist.org/packages/gglnx/twig-empty-coalesce)

This library adds a new [operator expression](https://twig.symfony.com/doc/2.x/templates.html#expressions) to Twig with three question marks (`???`) to check if the left value is defined, not null and not empty. Works the same way as the [`empty` test](https://twig.symfony.com/doc/2.x/tests/empty.html) and the `|default` filter.

```
{% set _null = null %}
{% set _empty = '' %}

{# Null Coalesce: Output will be string(0) "" because _empty is defined and not exactly null #}
{{ dump(_undefined ?? _null ?? _empty ?? 'fallback') }}

{# Default Filter: Output will be string(8) "fallback" because _empty is defined, but an empty string #}
{{ dump(_undefined | default(_null | default(_empty | default('fallback')))) }}

{# Same as the default filter, but much more readable #}
{{ dump(_undefined ??? _null ??? _empty ??? 'fallback') }}
```

Requirements
------------

[](#requirements)

- Twig &gt;=2.14 and Twig &gt;=3.0
- PHP &gt;=7.4

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

[](#installation)

The recommended way to install this loader is via [Composer](https://getcomposer.org/):

```
composer require gglnx/twig-empty-coalesce
```

You can install this library as extension in:

```
require_once '/path/to/vendor/autoload.php';

$twig = new \Twig\Environment($loader);
$twig->addExtension(new \Gglnx\TwigEmptyCoalesce\Extension\EmptyCoalesceExtension());
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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

Total

2

Last Release

1587d ago

### Community

Maintainers

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

---

Top Contributors

[![gglnx](https://avatars.githubusercontent.com/u/23519?v=4)](https://github.com/gglnx "gglnx (3 commits)")

---

Tags

twigtwig-extensiontwig-syntaxtwigtwig-extension

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gglnx-twig-empty-coalesce/health.svg)

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91492.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36763.2M221](/packages/twig-intl-extra)[twig/string-extra

A Twig extension for Symfony String

22046.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

22918.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21914.8M162](/packages/symfony-ux-twig-component)[bluetel-solutions/twig-truncate-extension

Twig Extension to truncate nested HTML, safely!

11100.0k](/packages/bluetel-solutions-twig-truncate-extension)

PHPackages © 2026

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