Catch twig parser errors

This commit is contained in:
Tim 2025-04-23 01:29:50 +02:00
parent 701bf6c1ed
commit 4e16444d2f

View File

@ -15,10 +15,14 @@ class TwigParser extends AbstractParser
public function parseView(string $content): string
{
try {
$arrayLoader = new ArrayLoader([
'index' => $content,
]);
$twig = new Environment($arrayLoader);
return $twig->render('index');
}catch (\Exception $exception) {
return sprintf('<pre><code class="hljs">%s</code></pre>', htmlspecialchars($exception->getMessage()));
}
}
}