2

我想根据登录用户通过前端路由器控制器从产品视图页面中删除 product_options_wrapper 块。

我知道我可以以编程方式附加一个新块,但我没有找到删除函数。:-(

试过了。像那样

$this->getLayout()->unsetBlock('product_options_wrapper');

$this->getLayout()->getBlock('product.info')->remove('product_options_wrapper');

但没有任何效果。

4

3 回答 3

8

为了使用其父块删除块,请使用以下代码

$this->getLayout()->getBlock('product.info')->unsetChild('product_options_wrapper');
于 2013-01-11T10:36:12.620 回答
7

如果 OP 代码使用了正确的块名称,即product.info.options.wrapper,而不是块别名,它应该可以工作。

$this->loadLayout();
//e.g. 
if (Mage::getSingleton('customer/session')->getCustomerGroupId() == [id]){
     $this->getLayout()->unsetBlock('product.info.options.wrapper');
}
$this->renderLayout();
于 2013-01-13T15:44:49.397 回答
6

这应该有效:

    $blockName = 'left'; // Add yours
    $update = Mage::app()->getLayout()->getUpdate();
    $removeInstruction = "<remove name=\"$blockName\"/>";
    $update->addUpdate($removeInstruction);

为什么?Mage_Core_Model_Layout在解析 XML的方法中查看文件,generateXml()并在为块设置删除的地方,将属性忽略添加到块中。在该方法generateBlocks()中,没有添加具有该属性的所有块。

于 2013-01-11T10:20:39.913 回答