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.
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
In my/app/cache, every time I edit a twig file I have to delete the 'prod' folder.
Is there a way to turn caching off?
Any help would be appreciated.
Although like stated use dev and if you really can't. Twig has a option for it. I have highlighted the line for you.
Quoted from http://symfony.com/doc/3.4/reference/configuration/twig.html#cache
cache
type: string default: '%kernel.cache_dir%/twig'
Before using the Twig templates to render some contents, they are compiled into regular PHP code. Compilation is a costly process, so the result is cached in the directory defined by this configuration option.
Set this option to null to disable Twig template compilation. However, this is not recommended; not even in the dev environment, because the auto_reload option ensures that cached templates which have changed get compiled again.
You can also leave in prod env, but set debug:true and this will force the templates to always recompile.
I recently started using Symfony and I want to edit the index page at the
http://localhost/my_project/web/
directory, but I cant find the Sprigs route for it. Also I don't have a index.? file in the web directory.
First of all, Symfony doesn't use index.php file as entry point. It uses app.php and app_dev.php as entry points for accordingly production and development environment.
For fresh Symfony installation, homepage route points to DefaultController:indexAction which you can find in src/AppBundle/Controller/DefaultController.
Also as you will find in this controller, this action uses default/index.html.twig template which you can find in app/Resources/views/ directory.
For more information please check Symfony Book and Cookbook, which you can find here. Especially you should go through the Book to get familiar with Symfony concepts.
I am using FOSUserBundle in some Symfony2 Projects.
To override the login page, I normally create a Twig file like this: /app/Resources/FOSUserBundle/views/security/login.html.twig.
In the past projects I created, this worked normally and did override the login page.
Recently, I have been working on a new Symfony project with a teammate. Overriding the login page worked in my environment but NOT in his environment. We tried uploading the project to a test server where it also didn't override the login page (It used to override it for other projects we tested).
We are using Symfony 2.7 with Linux Distros for all the environments. In my case, I use Ubuntu Server. My teammate runs Ubuntu Mate and the test server runs Ubuntu.
We checked folder permissions and ownerships and everything is ok.
Everything in the project works except this little twig override for the FOSUserBundle login page.
We already tried php clear:cache and manually deleting the cache folder.
We also tried this solution: What is the issue with not overriding templates in symfony2.6 and FOSUserBundle 1.3, where the answer suggests that the problem is the way PHP caches the file stats. This also didnt' work.
Any suggestions or maybe some PHP configs that we could try?
Thanks in advance,
It may be a problem with a case sensitivity.
Change it to /app/Resources/FOSUserBundle/views/Security/login.html.twig (lower case s -> upper case S). And then check by ls -l (also check your version control if relevant).
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.