Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout in Cakephp 3?

Good day everyone !
I have a Cakephp 3 project.

File src/Template/Layout/Default.ctp contains code (header, footer..) to import some vew like src/Template/User/index.ctp or src/Template/Posts/add.ctp automatically.

But it is Admin Panel, now I want build views for front-end, I dont want to use the same layout.How can I use different header/footer layout for src/Template/Home/index.ctp... ?.

Here is my folder

[1]

Tks for reading !

like image 613
Manh Nguyen Avatar asked Feb 05 '26 19:02

Manh Nguyen


1 Answers

You need the set the layout in your Controller or define some conditions on which the frontend View should be loaded in /src/View/AppView.php.

See the docs.

For the Controller approach:

// Set the layout.
$this->viewBuilder()->setLayout('admin');

// Before 3.4
$this->viewBuilder()->layout('admin');

// Before 3.1
$this->layout = 'admin';
like image 168
Marijan Avatar answered Feb 09 '26 07:02

Marijan