在代码中动态更换页面布局
假设要在category列表页根据传入category的条件(如id>10或者不大于10)动态改变其布局。方法是:
在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'); }}