I'm trying to override twig html error templates as per the symfony documentation
So I tried to override the views like for other third party bundles by creating the following files in 'templates/bundles/TwigBundle/Exception' :
error.html.twig
error404.html.twig
However the default html twig error templates show up when I trigger a 404 error in production mode.
Testing with the /_error/{statusCode} route in dev mode displays my custom templates correctly.
EDIT: I found out that it was an issue with FriendsOfSymfony/FOSRestBundle. Using composer require friendsofsymfony/rest-bundle dev-master solved the issue
Related
I want to do exactly this (see link below) - override the list__action_delete.html.twig template globally for the entire project.
But with the newer sonata-admin and symfony version (without the app-directory) I have no clue where to place the list__action_xxx.html.twig files
See:
SonataAdminBundle - rewrite action button teplates in config.yml
I usually see resource: contain a file path, but here I have a multiline string with yaml instead:
shop_admin_taxon:
resource: |
alias: sylius.taxon
section: shop
templates: AdminBundle:Taxon/Crud
except: ['show', 'index']
redirect: update
grid: shop_admin_taxon
type: sylius.resource
prefix: /
I didn't get any error messagaes about this code when it worked on Symfony 3.2.7 in another project. But now Symfony 3.4 gives me the following error when trying to read this configuration:
The file "alias: sylius.taxon section: shop templates: AdminBundle:Taxon" does not exist.
That's actually expected (since as far as I know you pass a resource locator to resource: and not the actual resource configuration), but why did it work?
Symfony is complex beast and allows a lot of tinkering with it's internals. The routing component is no exception of this and you can see usages which modify or even dynamically create routes on the fly.
This in particular looks like a Sylius extension to routing. If you are curious how precisely it works have a look at the relevant Symfony documentation page. The functionality is being provided by the SyliusResourceBundle with a custom loader.
With all this in mind it looks like you have a broken Sylius install as the custom routing loader is not working. It could be some version mismatch introduced by composer update (e.g. remove component A due to incompatibility with newer version of component B), or bundles not being enabled, or something similar. Make sure all Sylius bundles are installed and enabled
I'm trying to override the standard error.html.twig template provided by the Symfony2 Twig Bundle.
According to the docs, I just need to place a file error.html.twig in my app/Resources/TwigBundle/views/Exception folder and Symfony should use it.
I am able to specify specific error templates, like error404.html.twig, and those are used. But I'm looking to create a catch all template as well.
Anyone know what could be the issue?
The answer here seems to be clearing your cache after adding or editing your template.
A simple app/console cache:clear should resolve your problems also manually removing the app/cache directory should accomplish the same thing.
Should be simple enough. Everything works in my local environment, but not on my prod server (neither prod nor dev environment). I get an error that the FOS template cannot be found:
Unable to find template "FOSUserBundle::layout.html.twig".
My code is simple:
{% extends "FOSUserBundle::layout.html.twig" %}
I'm going from my local Windows machine to a Linux box. I've read case sensitivity might be the culprit, but it doesn't seem like it.
The FOS bundle is in the normal place: vendor/friendsofsymfony/user-bundle/FOS/UserBundle.
I'm having trouble diagnosing - any ideas? Did things get screwed up when I FTPd? Permissions issues? What are the common gotchas? I'm desparate!
Update: A clue. I ran assetic:dump and got
[RuntimeException]
".../app/Resources/FOSUserBundle/views/layout.html.twig" resource is hidden by a
resource from the "*******Bundle" derived bundle. Create a
".../app/Resources/*******Bundle/views/layout.html.twig" file to override the bundle
resource.
This question seems relevant.
Another update: I was using getParent() in my own bundle to override the templates. I switched to the first method in the docs but now the templates in app/resources simply aren't having an effect. It's going straight to the default form template with a white background.
Any ideas?
It was a upper/lower case/namespacing thing. I thought my local files were in sync with remotes but they were not.
Just check your whole directory & all namespaces in the FOS bundle!
I also encountered the problem and "solved" it by renaming my layout.html.twig inside my bundle's Resources/views folder to bundle-layout.html.twig and adapting my templates accordingly.
I resolved the resource is hidden by a resource error by moving the template in the good bundle extension.
Specifically from app/Resources/FOSUSerBundle/views/ChangePassword
to src/Application/Sonata/UserBundle/Resources/views/ChangePassword
I confounded FOSUser & SonataUser.
Recently, I've put the error.html.twig, error404.html.twig, exception.html.twig templates to the app/Resources/TwigBundle/views/Exception project directory to override Symfony2 error pages. In the prod environment it's working fine; in the dev environment also its overriding the default exception template, so it is very hard for debugging.
How can I get the default template working in the dev environment.
Overriding exception.html.twig is a mistake as it is only available in DEV environment, and you don't want a custom exception template.
Extract from official doc:
The debug-friendly exception pages shown to the developer can even be customized in the same way by creating templates such as exception.html.twig for the standard HTML exception page or exception.json.twig for the JSON exception page.