Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:40:52+00:00 2026-06-17T04:40:52+00:00

i want to customize the error pages in Symfony 2.0 I know that this

  • 0

i want to customize the error pages in Symfony 2.0

I know that this is done via overwriting the layouts in app/Resources/TwigBundle/views/Exception/* but I want to have different error pages for different routes.

I want one for backend and one for frontend.

How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:40:53+00:00Added an answer on June 17, 2026 at 4:40 am

    What you’ll need to do is not too difficult. Symfony allows you to explicitly specify which controller handles your exceptions. So, in your config.yml, you can specify the exception controller under your twig configuration:

    since Symfony 2.2

    twig:
       exception_controller:  my.twig.controller.exception:showAction
    
    services:
        my.twig.controller.exception:
            class: AcmeDemoBundle\Controller\ExceptionController
            arguments: [@twig, %kernel.debug%]
    

    up to Symfony 2.1:

    twig:
      exception_controller: AcmeDemoBundle\Controller\ExceptionController::showAction
    

    Then you can create a custom showAction that displays a custom error page based on a route:

    <?php
    namespace AcmeDemoBundle\Controller;
    
    use Symfony\Component\HttpKernel\Exception\FlattenException;
    use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController;
    
    class ExceptionController extends BaseExceptionController
    {
        public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
        {
            if ($this->container->get('request')->get('_route') == "abcRoute") {
                $appTemplate = "backend";
            } else { 
                $appTemplate = "frontend";
            }
    
            $template = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
            $code = $exception->getStatusCode();
    
            return $this->container->get('templating')->renderResponse(
                'AcmeDemoBundle:Exception:' . $appTemplate . '_' . $template . '.html.twig',
                array(
                    'status_code'    => $code,
                    'status_text'    => Response::$statusTexts[$code],
                    'exception'      => $exception,
                    'logger'         => null,
                    'currentContent' => '',
                )
            );
        }
    }
    

    Obviously you should probably customize the if statement where it tests the current route to fit your needs, but this should do it.

    You might want to add code that defaults to the normal Twig error pages if you don’t have a specific error template created. For more information, check out the code in

    Symfony\Bundle\TwigBundle\Controller\ExceptionController
    

    as well as

    Symfony\Component\HttpKernel\EventListener\ExceptionListener
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to customize the default error message This field is required when using
My app works with the Devise gem for authentication, but I want customize it
I want to customize a .NET build process so that I can run an
I want to customize ToolStripMenuItem by overriding OnPaint function. This is a MyToolStripMenuItem: public
I want to customize the 'new' and 'edit' pages in rails scaffolding. Where can
I want to customize sphinx search in such a way that I could keep
I would like to TOTALLY disable the twig error pages in Symfony. I do
i want to customize ValidationMessageFor which display error. when i run application, a get
I want to display 404 error page for that i have made error404.php file
I want to customize the error handling in symfony2 forms. If a error occured,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.