Magento get which layout being used on phtml files

Kamal picture Kamal · Jun 21, 2012 · Viewed 7.4k times · Source

Is there a way I could get which layout being used on a certain phtml files?

Here in my case, I want to check what layout being used on catalog/list.phtml, I used that information to make conditional "if" on the product image grid size.

I've tried to google it out. But all the result is just explaining about xml layout things. The closest clue I got is this thread

Magento get layout for given page

which stated the use of this snippet

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

but when I tried it on the phtml files, I got an exception error

UPDATE

joe's answer below has give me some more clue, the exception gone. But the behavior doesn't really what I need. That snippet of code seems to be just check whether the specified block is defined on the XML. What I really need is whether that block exist on a certain page.

In my case, I need to check what layout being used on catalog/product/list.phtml. if it's 3 columns, I'm gonna make the image resized smaller. If it 1 column, I'll make it bigger.

Is there any way I could do that??

Answer

djdy picture djdy · Jun 25, 2012

If I read the question correctly, then try:

$this->getLayout()->getBlock('root')->getTemplate();