I searched everywhere but unfortunately without result. The case is as following:
I'm using a general Symfony 4 codebase with basic TWIG template files. Next to that i have multiple domains who refer to the codebase, because of that reason I want to set the path to my TWIG files in the controller from my codebase:
return $this->render("path/to/domain/and/twig/temp", "domain variables");
This is not working and I can't find how to change my TWIG path withing my controller. Can somebody help with this?
Thanks!
Symfony uses app/Resources/views/ directory for templates. If you want to change you can configure it in config.yml as below.
twig:
# ...
paths: ["%kernel.project_dir%/templates"]
I have a problem with Symfony Flex and FOSUserBundle. I can't override default FOSUserBundle templates. I tried to do everything following the Symfony documentation, tutorials and nothing works. It's just like Twig won't take my layout.html.twig to render instead of default FOSUserBundle.
Templates dir tree looks like it should following new Symfony Flex structure:
- templates
- default
- FOSUserBundle
- views
- layout.html.twig
- base.html.twig
Maybe anyone has encountered similar problem with Symfony Flex.
Pull request that was merged in Symfony 3.4 at https://github.com/symfony/symfony/pull/24179 and available since 3.4-BETA1 and 4.0-BETA1 specifies that you need to place the template at templates/bundles/FOSUserBundle/layout.html.twig. PR description mentions exactly this usecase as its example.
In Symfony 3.3, it should work by placing the template in src/Resources/FOSUserBundle/views/layout.html.twig
templates
default
FOSUserBundle
layout.html.twig
it works for me
I don't anderstand why that doesn't work for me with symfony 4.0.8 in:
- templates
- FOSUserBundle
- layout.html.twig
but it works in
src
- Resources
- FOSUserBundle
- views
- layout.html.twig
I have a similar problem with symfony4 and fosUserBundle per to https://symfony.com/doc/current/templating/overriding.html,
for registration_content overriding i put my template file in templates\bundles\FOSUserBundle\Registration\register_content.html.twig
and it ready to works
hope work for you
I'm going to drop my answer here, because I am in a constant uphill battle with this bundle.
I copied the desired templates from the bundle in vendor and at first put them in,
project_root/src/Resources/FOSUserBundle
However after reading the documentation, it seems that it should be placed in project_root/templates/bundles/name_of_bundle/*.
However that didn't work because FOSUserBundle file structure is not adhering to symfonys conventions, you have to move things out of the views folder.
So rather than project_root/templates/bundles/name_of_bundle/views, move everything out of the views folder and into the parent name_of_bundle folder.
In your custom User bundle you must decalre the parent bundle
use Symfony\Component\HttpKernel\Bundle\Bundle;
class YourNameSpaceUserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
Note: Symfony Flex is alpha software; use it at your own risk
- templates
- FOSUserBundle
- layout.html.twig
Work for me too in Symfony 4.0.8 !
I'm using Symfony2.8 and when ever I use the command line for generating controllers and twig templates the templates are created under
MyBundle/Resources/views/home/home.html.twig
I want to follow the best practices suggested by symfony docs and have it inside of the
app/Resources/views/home/home.html.twig
I could just cut and paste the twig file and then change the {% extends %} if necessary, but then I would have lesser hair on my head because I would be pulling it out.
So what do I type in the prompt so that it generates the controller in the MyBundle as usual BUT the twig files would be under the global app/Resources/views folder
Thanks!
Edit: new extended question
After playing a little with the path for template generation i succeeded in placing the twig file inside the app/Resources/views/ folder.
Assuming that you have the standard architecture of a symfony2 app:
You could write the following path for the template when generator asks to specify the Templatename
Templatename (optional) [AppBundle:Post:get.html.twig]: ::../../../../app/Resources/views/Post/get.html.twig
I'm new to CakePHP and I need to integrate Twig for a project. First I installed the TwigView plugin (https://github.com/predominant/TwigView) and tried to follow the small set of instructions.
Installation
Plugin sources
I cloned the plugin repository in /app/Plugin/. A folder TwigView is created.
Twig sources
I placed Twig sources under /app/Plugin/TwigView/Vendor/ in a folder named Twig
Configuration
I added this to my /app/Config/bootstrap.php
CakePlugin::loadAll();
and this to AppController
public $viewClass = 'TwigView.Twig';
I also granted write privileges to everybody in /app/Plugin/TwigView/tmp/views
Problem 1
The application keeps asking for .ctp files, and I need to use my .tpl templates. I tried adding this in AppController
public $layout = 'default.tpl';
But it will complain, saying that it can't find default.tpl.ctp
Problem 2
How can I pass parameters to the twig templates from Cake controllers?
I am trying to override the translations in the default FOSUserBundle.en.yml. I have my User bundle as a child of the FOSUserBundle using the getParent method and I copied the FOSUserBundle.en.yml into the translations folder of the child bundle and nothing is being overridden. Can someone help me find out why this is?
I know I have to be missing something because I was able to override the layout.html.twig file easily doing the same thing.
I tried using php app/console cache:clear and that did not help.
It turned out that the translation file was overriding but the FOSUserBundle was after the child bundle in the AppKernel file. Because of how translations work the translation file from the FOSUserBundle was being loaded after the childs translation file, in turn overriding the child.
All I had to do was move the child bundle in the AppKernel file after the parent. This way it was the last translation file to be loaded.
Here is the documentation page I found this at:
http://symfony.com/doc/current/cookbook/bundles/override.html#override-translations
I've run into this before as well. Try manually deleting your cache/dev directory. I'm guessing your talking about the dev environment as cache:clear without parameters defaults to dev.