gglnx / twig-try-catch

Adds exception handling to Twig

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

try/catch for Twig

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.

About

Adds exception handling to Twig

License:MIT License


Languages

Language:PHP 100.0%