Skip to content

gglnx/twig-try-catch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.