gglnx/twig-try-catch

Adds exception handling to Twig

1.0.0 2022-01-05 15:10 UTC

This package is auto-updated.

Last update: 2024-04-05 20:16:01 UTC


README

Packagist

This library extends Twig with an tag to catch and handle exceptions:

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

Requirements

  • Twig >=2.14 and Twig >=3.0
  • PHP >=7.4

Installation

The recommended way to install this loader is via Composer:

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

This extension is extracted from Grav CMS. See the file headers and LICENSE file for copyright information.