Friday, February 18, 2022

[FIXED] How to enable a theme for all views?

Issue

I am working on a CakePHP 3 project and I'm new to CakePHP.

I have baked a theme MyTheme in plugins/MyTheme.

I have also configured default.ctp in plugins/MyTheme/src/Template/Layout/ directory and all css and js files in plugins/MyTheme/webroot/css/ and /plugins/MyTheme/webroot/js/ directories.

How do I enable this theme for all views (master theme) ?


Solution

[...] How do I enable this theme for all views (master theme) ?

By defining the theme to use (either via the $theme property (before CakePHP 3.1), or via the view builders theme() method) in a controller that all your applications controllers extend, which by default should be AppController.

Something along the lines of

//...

class AppController extends Controller
{
    // With CakePHP < 3.1
    public $theme = 'MyTheme';

    // With CakePHP >= 3.1
    public function beforeRender(\Cake\Event\Event $event)
    {
        $this->viewBuilder()->theme('MyTheme');
    }
}

See also



Answered By - ndm

No comments:

Post a Comment

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