CakePHP not recognizing Twig Layouts - php

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?

Related

Symfony 4 set Twig template path in controller

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"]

Override core files using module prestashop

Actually I'm a newbie to prestashop,
and I have changes in the following file in these locations
classes/Product.php
src/PrestaShopBundle/Controller/Admin/ProductController.php
src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
I have created a module named as My Kit while this module is configured all these changes should work..If the module is set to be disabled these changes should not affect in front end(I mean in admin panel)
For this I've created an override folder in my_kit module and place all those above mentioned files into this my_kit\override path..
like
my_kit\override\classes/Product.php
my_kit\override\src/PrestaShopBundle/Controller/Admin/ProductController.php
my_kit\override\src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
But it won't work for me :(
how should I do this one..
Someone help me out of this..
You can use php default copy function in your main file install function like below.
public function install()
{
copy(_PS_ROOT_DIR_."/modules/your module name/classes/Product.php",_PS_ROOT_DIR_."/override/classes/Product.php");
unlink(_PS_ROOT_DIR_."/cache/class_index.php");//because you need to delete this file after override
//Do same like this all other file.
}
Thanks,
I'm not really sure how you will work around the part with the custom module (maybe when the module is not configured, you will leave the override classes only defined, and when its configured, you will put the changes there)... still changes in the core files should be done like this - for the Product class:
Make a new file in (basefolder)/override/classes/Product.php
Define the class ass:
class Product extends ProductCore
Do your changes. (override functions, or adding new ones)
You can't override classes from src folder
PrestaShop 1.7 introduces the use of namespaces with its new
architecture, and in short, anything that has namespaces cannot be
overridden. The legacy architecture can still be overridden, though.
But in general, we advise against overriding code. It is better to
extend it. Also, overrides are currently forbidden in the
Symfony-based pages (namely, the Product page and the Modules page).
http://build.prestashop.com/news/prestashop-1-7-faq/#is-there-any-change-planned-to-the-override-system
If you want to override PrestaShop's classes and controllers, you can do it as in previous versions
http://doc.prestashop.com/display/PS16/Overriding+default+behaviors

Can't find protected folder in Yii2 Basic Package

I'm new to Yii2 and I was wondering where the protected/config/main.php sitting? Is web.php the main config file?
Respect to yii1 the (in part) configuration is in
basic\config\web.php
and part is in
basic\config\db.php
There is also an advanced template where you have frontend and backend application soon available with proper separated config area ..

Symfony2 commandline generation of twig templates under global folder

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

Symfony 3: Overriding Default UserBundle Templates

i want to override the Friendsofsymfony Userbundle Templates. I found already the documentation:
http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_templates.html
But i guess its not working in symfony3. The structur of the bundle is diffrent.
I think in the original its bundle/FOS/UserBundle/Ressources/views.
By me its vendor/friendsofsymfony/user-bundle/Resources/views.
I already try to copy this structur to the app folder. But it still not working.
thx for reading and maybe helping
See the Symfony documentation about overriding bundle templates:
When the AcmeBlogBundle:Blog:index.html.twig is rendered, Symfony actually looks in two different locations for the template:
app/Resources/AcmeBlogBundle/views/Blog/index.html.twig
src/Acme/BlogBundle/Resources/views/Blog/index.html.twig
To override the bundle template, just copy the index.html.twig template from the bundle to app/Resources/AcmeBlogBundle/views/Blog/index.html.twig (the app/Resources/AcmeBlogBundle directory won't exist, so you'll need to create it). You're now free to customize the template.

Categories