Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 在list.phtml中动态设置产品列表页面布局_Magento_Magento 1.7 - Fatal编程技术网

Magento 在list.phtml中动态设置产品列表页面布局

Magento 在list.phtml中动态设置产品列表页面布局,magento,magento-1.7,Magento,Magento 1.7,提前感谢, 我想动态更改产品列表页面布局 问题是,如果在list.phtml中单击网格链接,则list.phtml文件的布局应为2columns-right.phtml,如果单击list-link,则布局应为2columns-left.phtml 我已经为此使用了以下代码,但没有运气 if($this->getMode() == 'grid' && $this->getLayout()->getBlock('root')->getTemplate() !=

提前感谢,

我想动态更改产品列表页面布局

问题是,如果在list.phtml中单击网格链接,则list.phtml文件的布局应为2columns-right.phtml,如果单击list-link,则布局应为2columns-left.phtml

我已经为此使用了以下代码,但没有运气

if($this->getMode() == 'grid' && $this->getLayout()->getBlock('root')->getTemplate() != 'page/2columns-left.phtml'):
$this->getLayout()->getBlock('root')->setTemplate('page/2columns-right.phtml');
elseif($this->getMode() == 'list' && $this->getLayout()->getBlock('root')->getTemplate() != 'page/2columns-right.phtml'):
$this->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
endif;

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

以前有人这样做过吗?

我认为您将此代码放在根块已经加载的位置

一种可能是使用css,将列表置于3列模式,隐藏不需要的列+根据“$this->getMode()”使用css更改主列的宽度

另一种方法是创建控制器,为列表和网格生成整个正文页面,并在更改模式时使用AJAX填充页面