假设要在category列表页根据传入category的条件(如id>10或者不大于10)动态改变其布局。方法是:
在Block类的回调方法_prepareLayout中调用类似的代码
可以用函数
$this->getLayout()->getBlock('root')->setAttribute('template','page/2rows-1column.phtml');
替换
$this->getLayout()->getBlock('root')->setTemplate('page/2rows-1column.phtml');
在Block类的回调方法_prepareLayout中调用类似的代码
protected function _prepareLayout(){
parent::_prepareLayout();
$cid = $this->getCurrentCategory()->getId();
if($cid>10) {
$this->getLayout()->getBlock('root')->setTemplate('page/2rows-1column.phtml');
} else {
$this->getLayout()->getBlock('root')->setTemplate('page/another.phtml');
}
}
可以用函数
$this->getLayout()->getBlock('root')->setAttribute('template','page/2rows-1column.phtml');
替换
$this->getLayout()->getBlock('root')->setTemplate('page/2rows-1column.phtml');