문제

I'm trying to make custom error pages in symfony2 but having problems using my site theme/layout within error.html.twig

As in stated here: http://symfony.com/doc/current/cookbook/controller/error_pages.html

I've overridden the error file and put my own into app/Resources/TwigBundle/views/Exception/error.html.twig. If I use static content this all works fine, but I'd like to use {% extends '::base.html.twig' %} like I do with all other pages, so I can copy my current layout and styles.

base.html.twig is located at app/Resources/views/base.html.twig. How do I go about extending this template?

Also, just out of curiosity, is there any way of overriding error pages from within one of my bundles without making a 'TwigBundle' bundle especially for it?

UPDATE

Ok, solved this with the help of 'wouter J'. It turns out the file was being found but the file it was extending was using is_granted. Adding app.user and to the if statement as it says in the docs solved it.

도움이 되었습니까?

해결책

The ::base.html.twig syntax is not relative. That means it'll work everywhere.

The full syntax for template paths is BundleName:DirName:FileName. So AcmeDemoBundle:Page:home.html.twig refers to @AcmeDemoBundle/Resources/views/Page/home.html.twig.

If the DirName is not used, e.g. AcmeDemoBundle::layout.html.twig, it'll be resolved to @AcmeDemoBundle/Resources/views/layout.html.twig.

If the BundleName is not used, it is assumed the template lives in app/Resources/views.

So ::base.html.twig just refers to the absolute path app/Resources/views/base.html.twig (this is not absolute, since I don't know the absolute path to the app dir in your case, but it'll be absolute when Symfony does it).

In short: You can just use ::base.html.twig

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top