And*_*s B 2 magento magento-1.6
我想根据logedin用户通过前端路由器控制器从产品视图页面中删除product_options_wrapper块.
我知道我可以以编程方式附加一个新块但我没有找到删除功能.:-(
试过了...... 像那样
$this->getLayout()->unsetBlock('product_options_wrapper');
$this->getLayout()->getBlock('product.info')->remove('product_options_wrapper');
Run Code Online (Sandbox Code Playgroud)
但没有任何作用.
要使用其父块删除块,请使用以下代码
$this->getLayout()->getBlock('product.info')->unsetChild('product_options_wrapper');
Run Code Online (Sandbox Code Playgroud)
这应该工作:
$blockName = 'left'; // Add yours
$update = Mage::app()->getLayout()->getUpdate();
$removeInstruction = "<remove name=\"$blockName\"/>";
$update->addUpdate($removeInstruction);
Run Code Online (Sandbox Code Playgroud)
为什么?查看解析XML Mage_Core_Model_Layout的方法中的文件generateXml()以及为块设置remove的位置,将属性ignore添加到块中.在该方法generateBlocks()中,不添加具有该属性的所有块.
如果OP代码使用正确的块名称(即product.info.options.wrapper)而不是块别名,则OP代码应该可以工作.
$this->loadLayout();
//e.g.
if (Mage::getSingleton('customer/session')->getCustomerGroupId() == [id]){
$this->getLayout()->unsetBlock('product.info.options.wrapper');
}
$this->renderLayout();
Run Code Online (Sandbox Code Playgroud)