# Load a different layout in PagesController

**URL:** <https://discourse.cakephp.org/t/load-a-different-layout-in-pagescontroller/6644>\
**Category:** Need Help\
**Created:** [September 20, 2019, 4:59pm UTC](https://discourse.cakephp.org/t/load-a-different-layout-in-pagescontroller/6644 "2019-09-20T16:59:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranago](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@ranago](https://discourse.cakephp.org/u/ranago)\
**Post date:** [September 20, 2019, 4:59pm UTC](https://discourse.cakephp.org/t/load-a-different-layout-in-pagescontroller/6644/1 "2019-09-20T16:59:48Z")

</div>

I have the method beforeFilter where I load a layout but in the method “admin” I want to load a different layout and it doesn’t let me do it.

![php%20(edpap)%20-%20Sublime%20Text](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/b/ba0b958876ce057a872704380332eeb7b83000d5.png)

If I delete the beforeFilter method, I don’t load any layout. How can i fix this? Thank you

---

<div class="post-metadata">

**Author:** ![chris69m](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@chris69m](https://discourse.cakephp.org/u/chris69m)\
**Post date:** [August 30, 2020, 9:09pm UTC](https://discourse.cakephp.org/t/load-a-different-layout-in-pagescontroller/6644/2 "2020-08-30T21:09:39Z")

</div>

You will need to enable first path to “admin” or anything in …/Config/core.php  
Configure::write(‘Routing.prefixes’, array(‘admin’, ‘agent’, ‘moderator’));

---

<div class="post-metadata">

**Author:** ![debendra986](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@debendra986](https://discourse.cakephp.org/u/debendra986)\
**Post date:** [August 31, 2020, 4:36am UTC](https://discourse.cakephp.org/t/load-a-different-layout-in-pagescontroller/6644/3 "2020-08-31T04:36:06Z")

</div>

You need to load your default layout in initialize methode

> public function initialize() {  
> parent::initialize();  
> $this-\>viewBuilder()-\>layout(‘publico’);  
> }

then in any method you can override the default layout

> ```
> public function admin() {
> $this->viewBuilder()->layout('privado');
> }
> 
> ```
