以编程方式从布局中删除块 [英] Programmatically remove block from layout

查看:56
本文介绍了以编程方式从布局中删除块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to remove the product_options_wrapper block from the product view page according to the logedin user via frontend router controller.

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

I know that I can programmatically append a new block but I didn't find a remove function. :-(

试图……像这样

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

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

但是什么都行不通.

推荐答案

如果OP代码使用正确的块名称( product.info.options.wrapper ),则OP代码应该起作用.到块别名.

The OP code should work, if it used the correct block name, which is product.info.options.wrapper, as opposed to the block alias.

$this->loadLayout();
//e.g. 
if (Mage::getSingleton('customer/session')->getCustomerGroupId() == [id]){
     $this->getLayout()->unsetBlock('product.info.options.wrapper');
}
$this->renderLayout();

这篇关于以编程方式从布局中删除块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆