Set a Custom Layout in CakePHP 3 & 4
Set a Custom Layout in CakePHP 3 & 4
Setting a different layout in CakePHP is very easy. In your function, simply specify the new layout:
Note: These are the same for CakePHP3 and CakePHP4.
$this->viewBuilder()->setLayout('template-2');
Note: you must have a corresponding file in your \templates\layout folder. For CakePHP3, the folder is \src\Template\layout\.