title: Custom 404 error template in twig 2.5 with symfony 4.1
body: <p>I created customs Twig templates for http error display to keep the site design unified by extending my base layout. (I want to keep my navigation menu and display the error, unlike the regular error messages)</p>
  
  <p>It's working as expected but for the 404.</p>
  
  <p>In the navigation menu of my base layout, I have a lot of <code>is_granted('SOME_ROLES')</code> to display the availables sections of the site depending of user's rights. When a 404 is thrown, the navigation menu is displayed as if the user is disconnected : <code>{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}</code> being false.</p>
  
  <p>After some searches, I found that the router is executed before the firewall. Since no route is found when a 404 is thrown, the firewall isn't executed and the rights aren't send to the template.</p>
  
  <p>The only workaround I found (<a href="https://github.com/symfony/symfony/issues/5320#issuecomment-56401080" rel="nofollow noreferrer">source from 2014</a>) is to add at the very bottom of the routes.yaml file this route definition :</p>
  
  <pre><code>pageNotFound:
      path: /{path}
      defaults:
          _controller: App\Exception\PageNotFound::pageNotFound
  </code></pre>
  
  <p>Since every other routes hasn't match, this one should be the not found.</p>
  
  <p>The controller :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Exception;
  
  use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  
  class PageNotFound
  {
      public function pageNotFound()
      {
          return (new NotFoundHttpException());
      }
  }
  </code></pre>
  
  <p>Because a controller is executed, the firewall is executed and the 404 error page is shown as I expected (hooray !).</p>
  
  <p>My question is : Is there any <strong>proper</strong> way to fix that issue instead of that workaround?</p>