开发者

Magento Store - Remove Block using Update XML

I am using this code in my template file to display a static block in my left sidebar:

<?= $this->getLayout()->createBlock('cms/block')->setBlockId('leftSB1')->toHtml() ?>

I would like to exclude the block from one of my CMS pages. How do I do this?

I开发者_JAVA技巧 think it requires adding code to the 'Layout Update XML' section but I'm not sure what exactly.


Someone else can correct me here, but I'm fairly sure that you're going to have trouble trying to accomplish this given the way you called the block. Normal layout updates allow you to remove blocks, but those are blocks that were also created with the layout (e.g. the Layout object knows about them after you call loadLayout()).

In your case, you create the block on the fly and then immediately use it to echo some HTML. If you want to be able to delete it with layout updates, try moving it into the layout files first, then use the normal layout block removal method:

<reference name="your_parent_block_name">
   <remove name="leftSB1"/>
</reference>

Otherwise, you could hide it either in the PHP (By setting some global variable and checking it before outputting the block. Poor form but it might work.) or in CSS. Let me know if any of these work for you.

Thanks, Joe


Include the block in your layout instead:

<cms_page>
  <reference name="left">
    <block type="cms/block" name="leftSB1">
      <action method="setBlockId"><id>leftSB1</id></action>
    </block>
  </reference>
</cms_page>

And then $this->getChildHtml('leftSB1') in your sidebar, if you're not including children automatically.

(and then remove it from the particular page as in the previous answer)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜