简体   繁体   中英

Use bundle error templates in Symfony 3 app

I have a MyBundle bundle which I use in many Symfony applications. This bundle provides common things which are shared across these applications, such as Controllers, Entities, templates, etc.

I would like the bundle to provide error templates as well. I tried to put the templates in MyBundle/Resources/TwigBundle/views/Exception folder but the application does not use them.

When I copy TwigBundle folder from MyBundle/Resources into app/Resources then the templates are used as expected. However I do not want to copy the templates into every application's app/Resources folder.

Is it possible to override error templates using MyBundle/Resources instead of app/Resources?

TwigBundle always by default checks directory app/Resources/TwigBundle/views/Exception/ for templates.

If you want to use custom directory you have to override ExceptionController . You can do this in config

// app/config/config.yml
twig:
    exception_controller: MyBundle:Exception:showException

Default Twig ExceptionController can be found here .

Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM