Magento获取在phtml文件上使用哪种布局 [英] Magento get which layout being used on phtml files

查看:86
本文介绍了Magento获取在phtml文件上使用哪种布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让某些phtml文件使用哪种布局?

在这种情况下,我想检查一下catalog/list.phtml上使用的布局,我使用该信息在产品图像网格尺寸上添加条件"if".

我试图用谷歌搜索它.但是所有结果只是在解释xml布局问题.我得到的最接近线索是该线程

Magento获取给定页面的布局

说明了此代码段的使用

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

但是当我在phtml文件上尝试时,出现了异常错误

更新

乔的以下回答为我提供了更多线索,但异常消失了.但是这种行为并不是我真正需要的.该代码段似乎只是检查是否在XML上定义了指定的块.我真正需要的是该块是否存在于特定页面上.

就我而言,我需要检查catalog/product/list.phtml上使用的布局.如果是3列,我将缩小图像的尺寸.如果是1列,我会加大它.

有什么办法可以做到吗?

解决方案

如果我正确阅读了问题,请尝试:

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

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??

解决方案

If I read the question correctly, then try:

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

这篇关于Magento获取在phtml文件上使用哪种布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆