PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 5, 2022

[FIXED] CakePHP Bake from different templates when using prefix

 January 05, 2022     cake-bake, cakephp, cakephp-3.0, cakephp-bake     No comments   

Issue

When I currently use ./cake.bat bake template Genres or ./cake.bat bake template Genres --prefix admin, then the templates are used from these locations:

cakephp\bake\src\Template\Bake\Template\view.twig
cakephp\bake\src\Template\Bake\Template\index.twig
cakephp\bake\src\Template\Bake\Template\add.twig
cakephp\bake\src\Template\Bake\Template\edit.twig

I want to different versions of all these templates when I bake with the admin prefix. I tried creating a Bake Theme.

  • I ran ./cake.bat bake plugin AdminTheme
  • Then I placed the desired template files in plugins/AdminTheme/templates/Bake/Template/.
  • Ran ./cake.bat bake template Genres --theme AdminTheme
  • Got Error: "AdminTheme" is not a valid value for --theme. Please use one of "Bake, Migrations, WyriHaximus/TwigView"

Solution

Prefixes won't affect the template source, the path is pretty much hardcoded in \Bake\Shell\Task\TemplateTask::getContent(). One way to uses different templates is to bake each action separately, and use the action argument, and optionally the alias argument to use the default name for the output, something along the lines of this:

bin\cake bake template Genres admin_index index --prefix Admin

That would use the Template/admin_index.ctp|twig file, and write to Template/Admin/Genres/index.ctp.

As for your bake theme, the template folder structure in your theme plugin has to be:

AdminTheme/src/Template/Bake/Template/

not

AdminTheme/templates/Bake/Template/

Also make sure that your plugin is actually being loaded, ie check that $this->addPlugin('AdminTheme'); exists in your Application class' bootstrap() method, or for earlier versions Plugin::load('AdminTheme'); in your config/bootstrap.php file.

See also Bake Cookbook > Extending Bake > Creating a Bake Theme



Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing