# Path from Theme overrides Path from Layout

**URL:** <https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640>\
**Category:** Need Help\
**Created:** [September 19, 2019, 9:03pm UTC](https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640 "2019-09-19T21:03:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![M3Y3R](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@M3Y3R](https://discourse.cakephp.org/u/M3Y3R)\
**Post date:** [September 19, 2019, 9:03pm UTC](https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640/1 "2019-09-19T21:03:11Z")

</div>

Hi,

i need a little bit Help.

I installed a Theme (cakephp-adminlte-theme) via Plugin, located under:  
`vendor/maiconpinto/cakephp-adminlte-theme`

Now, i have created a Default-Page for the Admin-User. This is located under:  
`src/Template/Layout/admin.ctp`

This works correctly, but the admin.ctp includes a file called “nav-top.ctp” via element()-Methode.  
Now, i created a file “nav-top.ctp” under:  
`src/Template/Admin/Element/nav-top.ctp`

But the file will not load …

I searched for this Issue, and located the incorrect Path-Order in:  
`vendor/cakephp/cakephp/src/View/View.php`

When i output the content of $paths, then it returned the following:  
[  
(int) 0 =\> ‘/vendor/maiconpinto/cakephp-adminlte-theme/src\Template’,  
(int) 1 =\> ‘\src\Template’,  
(int) 2 =\> ‘\vendor\cakephp\cakephp\src\Template’  
]

I want the second Element on Position one, so that the following result will be returned:  
[  
(int) 0 =\> ‘\src\Template’,  
(int) 1 =\> ‘/vendor/maiconpinto/cakephp-adminlte-theme/src\Template’,  
(int) 2 =\> ‘\vendor\cakephp\cakephp\src\Template’  
]

Can anybody help me or is this a Bug in the Core?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 20, 2019, 4:23am UTC](https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640/2 "2019-09-20T04:23:05Z")

</div>

This path search order is how it’s supposed to work. A main use for plugins is to provide themes, as you’ve got here, and a theme really only works if it overrides the default views.

But there’s not enough information here to know whether this is actually your problem. The `src/Template/Layout/admin.ctp` is something you have created, right? How, specifically, are you trying to reference the `nav-top` element? And when you say “the file will not load”, do you mean that it’s not loading any such element at all, or it’s loading the one from the `adminlte` theme instead of yours?

---

<div class="post-metadata">

**Author:** ![M3Y3R](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@M3Y3R](https://discourse.cakephp.org/u/M3Y3R)\
**Post date:** [September 20, 2019, 3:35pm UTC](https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640/3 "2019-09-20T15:35:30Z")

</div>

The File `src/Template/Layout/admin.ctp` was created by me, correct.  
The File `nav-top.ctp` is included via `<?php echo $this->element('nav-top'); ?>` in `src/Template/Layout/admin.ctp`.

The Method loads the nav-top.ctp from AdminLTE-Theme, located under:  
‘/vendor/maiconpinto/cakephp-adminlte-theme/src\Template’

I want to load the `nav-top.ctp` from `\src\Template`

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 21, 2019, 7:05pm UTC](https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640/4 "2019-09-21T19:05:01Z")

</div>

Two problems here, I think.

First, I don’t think anything is ever going to find `src/Template/Admin/Element/nav-top.ctp` by calling `$this->element('nav-top')`. Nothing in the call there is indicating that it should look in your `Admin` folder, and the directory structure seems wrong anyway.

Second, based on this setup, it’s always going to load the `nav-top.ctp` from the AdminLTE theme.

I think the solution to both is to reorganize things slightly. Assuming that you only need your version to be used in your admin layout, move your the file to `src/Template/Element/Admin/nav-top.ctp`, and call it with `$this->element('Admin/nav-top')` in your layout.

---

<div class="post-metadata">

**Author:** ![M3Y3R](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@M3Y3R](https://discourse.cakephp.org/u/M3Y3R)\
**Post date:** [September 22, 2019, 10:50am UTC](https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640/5 "2019-09-22T10:50:00Z")

</div>

Hi Zuluru,

the Method `$this->element('nav-top');` calls the Methode  
`$this->_getElementFileName($name, $pluginCheck);` from `vendor/cakephp/cakephp/src/View/View.php`.

This Method in turn calls `$this->_paths($plugin);`  
The Method `$this->_paths($plugin);` returned a Array to `_getElementFileName()` with following content  
 ![22-13-01-18](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/4/45b38dd9c38baa6f804a01ac9c22ef6198299bf4.png)

On Row later, in the Method `_getElementFileName` you can see a call to the Method `_getSubPaths` wich returned the following array:  
 ![22-13-02-53](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/4/4a08044618b9a28c43b2892257b2e885ea0f3716.png)

Now both arrays have been traversed. At the same time, `file_exists()` checks if the file exists.

 ![Unbenannt](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/a/a17800cccece388d4448aa053c04c6c227a6f0e5.png)

So, the Methode `_getElementFileName()` returned the wrong path:  
`/vendor/maiconpinto/cakephp-adminlte-theme/src\Template\Element\nav-top.ctp`

The Mistake is in the Method `$this->_paths($plugin);` This returned the array:  
 ![22-13-01-18](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/4/45b38dd9c38baa6f804a01ac9c22ef6198299bf4.png)

However, the method would have to return the following array:  
 ![22-13-04-56](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/c/c62123565e2a34f22b2c3df59ec2c3757e92bde1.png)

So the the File `nav-top.ctp` is loaded from source:  
`src/Template/Admin/Element/nav-top.ctp`

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [September 22, 2019, 2:20pm UTC](https://discourse.cakephp.org/t/path-from-theme-overrides-path-from-layout/6640/6 "2019-09-22T14:20:01Z")

</div>

The point remains that if it returned directories in the order that you think it should, then no plugin would ever be able to override a base implementation, and the ability to do is pretty key to how many plugins operate. This is not a CakePHP bug, in other words, it’s a problem with your implementation.
