gglnx / twig-try-catch
Adds exception handling to Twig
Installs: 20 491
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.5
- twig/twig: ^2.14|^3.0
Requires (Dev)
README
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.