I am struggling with a problem while trying to make a custom error page in Silex .
According to what I found in this link: http://refactoring.us/silex/custom-error-pages-with-silex-and-twig/
I am trying to customize the 404 error page in my application. Everything works fine until I start using helpers in my branch template.
Sample code for the 404 error page template is as follows:
{% extends "layout.html.twig" %} {% block main %} <div id="error404"> <h2>{{ app.translator.trans('page404.title') }}</h2> <p>{{ app.translator.trans('page404.para1') }}</p> <p class="btn-footer"> <a href="{{ url('home') }}" class="btn">{{ app.translator.trans('page404.button') }}</a> </p> </div> {% endblock %}
PHP code for handling errors in my Silex application:
$app->error(function (\Exception $e, $code) use($app) { switch ($code) { case 404: $message = $app['twig']->render('error404.html.twig'); break; default: $message = $app['twig']->render('error500.html.twig'); } return new Response($message, $code); });
As soon as i remove
{{url ('home')}} (This helper and route work fine in other cases!) I get the appropriate site rendering, but without translations.
With the assistant, I get the following error:
Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\RouteNotFoundException' with message 'Route "" does not exist.' in D:\projects\projectname\application\vendor\symfony\routing\Symfony\Component\Routing\Generator\UrlGenerator.php:119 Stack trace: #0 D:\projects\projectname\application\vendor\symfony\twig-bridge\Symfony\Bridge\Twig\Extension\RoutingExtension.php(45): Symfony\Component\Routing\Generator\UrlGenerator->generate(NULL, Array, false) #1 D:\projects\projectname\application\vendor\twig\twig\lib\Twig\Environment.php(327) : eval()'d code(68): Symfony\Bridge\Twig\Extension\RoutingExtension->getPath(NULL, Array) #2 D:\projects\projectname\application\vendor\twig\twig\lib\Twig\Template.php(265): __TwigTemplate_ca53e56b87abd45da5c34a79d4c2ce34->doDisplay(Array, Array) #3 D:\projects\projectname\application\vendor\twig\twig\lib\Twig\Template.php(239): Twig_Template->displayWithErrorHandling(Array, Array) #4 D:\projects\projectname\application\vendor\twig\twig\lib\Twig\Envir in D:\projects\projectname\application\vendor\twig\twig\lib\Twig\Template.php on line 280
Therefore, I need to be guided here, what could be a possible reason for this, what causes it, and steps to solve this problem. All help was appreciated.
url twig fatal-error helpers silex
user1772403 Oct 24 2018-12-12T00: 00Z
source share