PHPackages                             gglnx/twig-try-catch - 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-try-catch

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

gglnx/twig-try-catch
====================

Adds exception handling to Twig

1.0.0(4y ago)434.6k↓57%1MITPHPPHP &gt;=7.2.5

Since Jan 5Pushed 4y ago2 watchersCompare

[ Source](https://github.com/gglnx/twig-try-catch)[ Packagist](https://packagist.org/packages/gglnx/twig-try-catch)[ RSS](/packages/gglnx-twig-try-catch/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

`try/catch` for Twig
====================

[](#trycatch-for-twig)

[![Packagist](https://camo.githubusercontent.com/226972a1311dfbf01236b533450833dd771f950e9c3bf8bb9ef4684bad0fbe67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67676c6e782f747769672d7472792d63617463682e737667)](https://packagist.org/packages/gglnx/twig-try-catch)

This library extends [Twig](https://twig.symfony.com/) with an tag to catch and handle exceptions:

```
{% try %}
  {{ throws_exception() }}
{% catch %}
  {# The exception can be accessed using `e` #}
  User Error: {{ e.message }}
{% endcatch %}
```

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-try-catch
```

You can install this library as extension in:

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

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

Acknowledgements
----------------

[](#acknowledgements)

This extension is extracted from [Grav CMS](https://github.com/getgrav/grav). See the file headers and `LICENSE` file for copyright information.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

1641d 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 (2 commits)")

---

Tags

twigtwig-extensiontwigtwig-extension

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gglnx-twig-try-catch/health.svg)

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

###  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)
