Magento gets the layout used in phtml files

Is there a way to get which layout is used in specific phtml files?

Here, in my case, I want to check which layout is used in the /list.phtml directory, I used this information to make a conditional “if” on the size of the product image grid.

I tried to do this. But the whole result is just an explanation of things in the xml layout. The closest key I received is the stream

Magento get layout for this page

which talked about using this snippet

$left_block = $this->loadLayout()->getLayout()->getBlock('left'); 

but when i tried it in phtml files i got an exception error

UPDATE

joe answer below gave me some more clues, exception passed. But the behavior is not quite what I need. This piece of code seems to just check if the specified block is defined in XML. I really need to see if this block exists on a specific page.

In my case, I need to check which layout is used in the /product/list.phtml directory. if it is 3 columns, i'm going to reduce the size of the image. If it is 1 column, I will do it more.

Is there any way to do this?

+4
layout e-commerce magento
source share
2 answers

If I read the question correctly, try:

 $this->getLayout()->getBlock('root')->getTemplate(); 
+11
source share

Remove loadLayout() :

 $left_block = $this->getLayout()->getBlock('left'); 

By the time you are in the PHTML file, the layout is already loaded.

In PHTML files, $ this refers to the Mage_Core_Block_Template class (or to the class that extends it). This class does not have a specific loadLayout () method, so you get an exception; instead, loadLayout () is part of Mage_Core_Controller_Varien_Action .

+3
source share

All Articles