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)07.4k↓61.1%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 2d 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 47% 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

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

[symfony/ux-twig-component

Twig components for Symfony

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

Live components for Symfony

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