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.
Related
I'm starting to develop a project that will be quite big (hear lots of files) and I want to have an organization that's different from Symfony's default one: instead of having one dir for all my controllers, another for all my forms, etc, I want to have one dir per functionality, ie a directory for my homepage which will contain the controller, the templates, another dir for the blog page with the controller, forms and templates, and so on.
I tried what was explained in this (old) answer, and it didn't work : my routes weren't recognized, and a php bin/console debug:router showed they weren't listed anymore.
I feel I will have something to adapt in my routes.yaml file, which looks like this for now, and which explains why it doesn't work because it explicitely searches in the src\Controller directory:
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute
I looked in the documentation I found, but I didn't find anything useful (I think I will have to remove the path and change it to something else, but I don't know what yet.
The above solutions are only for differentiating controller and template files. But For Entity, Events, and Forms it will not work.
It seems like you want to separate files for each module or functionality. For example, settings.yaml, controller, entity, forms, events, etc...
For that Symfony provides a Bundle feature. You can create a new Bundle in Symfony and use it as a separate feature. For more details please read this link
I'm working in symfony 2.5 with propel for my project.
I need to add a behavior to fos_user table so I need a way to override the original schema file in my src/ directory. Defining my project as a child of FOSUserBundle does work but this is not what I want.
Is there another way?
you can copy the original schema file to your app directory
and add the behavior you need. The way is exactly like overriding
any twig templates from vendors.
I'm having trouble finding the correct tutorial for me. I'm trying to have a controller-configuration in my bundle in Resources/config/someconfig.yml. I already adjusted it to a .yml extension. Now I'm searching a solution to access this configuration inside a twig exception controller (404-pages) and merge this configuration with the config.yml in app/config/.
Can anybody help me with a tutorial link or tips?
Thank you!
To get Resources/config/someconfig.yml config you can create DI extension: http://symfony.com/doc/current/cookbook/bundles/extension.html
I think this can help you to get configuration value in view: How to get config parameters in Symfony2 Twig Templates
As an alternative you can override Exception controller (get configuration parameters there and pass them to the view): http://symfony.com/doc/current/cookbook/controller/error_pages.html#replace-the-default-exception-controller
For merging configurations among independent bundles you should use prependExtensionConfig method and PrependExtensionInterface interface.
Documentaion page How to Simplify Configuration of multiple Bundles explains this technique in great detail.
Creating controller with
app/console doctrine:generate:crud
ends up with an error:
[Twig_Error_Loader]
Unable to find template "crud/views/layout.html.twig.twig"
(looked into: ...\vendor\sensio\generator-bundle\Sensio\Bundle\GeneratorBundle\Command/../Resources/skeleton,
...\vendor\sensio\generator-bundle\Sensio\Bundle\GeneratorBundle\Command/../Resources).
In the requested directory I can't find a template like "crud/views/layout.html.twig.twig".
Any help appreciated,
Use find text in the files with Netbeans or Notepad++ for searching next string:
layout.html.twig.twig
maybe you have this template name in any parent templates or your controllers.
Or for test, try to create crud/views/layout.html.twig.twig template and generate crud again.
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.