Question

All of the product category pages in our store are two column (nav left) format. One of our categories needs to have an element in the left hand column removed. Every single other page that has this left-hand column has this element in it, and needs to continue to do so, but for these few minor subcategories.

The previous developer had it set up so that the element was in a banner, and positioned with a widget via the CMS. It's set up to show up on a ton of different pages (eg: Categories is set to All), and we want to keep it like that so that we don't have to add new categories to a specific list as new ones are made by product managers and whatnot.

I couldn't find a way to remove banners nor widgets from a specific category, so I recreated the banner as a static block, intending to use the Custom Layout Update to remove it by its name.

<reference name="left">
<remove name="my_static_block_id"></remove>
</reference> 

This does not work!

I also tried unsetChildren:

<action method="unsetChildren"/>

This removed everything from the left column (not desirable)

Is there some way to do this? Perhaps somewhere I did not look? Thank you.

Was it helpful?

Solution

So what your trying to achieve is difficult because of the way widgets are added to the page, when a widget is saved it's layout XML update is automatically generated HOWEVER the name that is generated is just an random hash generated in the file below.

Mage_Widget_Model_Widget_Instance::generateLayoutUpdateXml

$hash = Mage::helper('core')->uniqHash();
$xml .= '<block type="' . $this->getType() . '" name="' . $hash . '"' . $template . '>';

This is then later saved to the database for example in my case the random name was 9d10a0d6931d18586a907b201633d878 which you can see is in the below image.

enter image description here

So although it's probably not very practical to do so in theory there is a way you could do this without touching any code you could create the widget search for the update record in the database table core_layout_update get your new block name and then do for example <remove name="9d10a0d6931d18586a907b201633d878"/> However if you make any change to the widget the XML and name will refresh and you would need to update the name references once again. I tried unsetChild and that didn't seem to work I suspect that is due to the order in which the XML is processed for widgets.

I think you have two real options:

1) Add a new text_list to the left column, right column or anywhere else you would want to add widgets and then mabey remove them on a page. You can do this in your themes local.xml like this.

    <reference name="left">
<block type="core/text_list" name="widgets_left" as="widgets_left" translate="label">
                        <label>Widgets Left</label>
                    </block>
</reference>

This will add a new option in the backend as in the image which you can then add widget instances too or just remove if you need to by name as you have the widgets_left name as a reference.

e.g enter image description here

You can then do either on the below in the specific category you'd like them removed from:

<reference name="left">
<action method="unsetChild"><name>widgets_left</name></action>
</reference>

<remove name="widgets_left"/>

2) Alternatively you could just add them in Via XML like below, but it sounds to me like you want as much control as possible via the CMS and why not for me widgets are underused.

<reference name="left">
            <block type="cms/block" name="cms_left_block_name">
                <action method="setBlockId"><block_id>my_block_identifier_from_magento_backend</block_id></action>
            </block>
        </reference>

You will then have a reference fixed as "cms_left_block_name" which you can use to either perform a remove or unsetChild.

OTHER TIPS

You're close, you need to know the NAME of the block added, and the name of it's parent.

For example, a block added to the parent block "left" as follows:

<reference name="left">
    <block type="cms/block" name="my_block_name">
         <action method="setBlockId"><block_id>some_static_block_identifier</block_id></action>
    </block>
</reference>

Would be removed as follows:

<reference name="left">
    <action method="unsetChild"><child>my_block_name</child></action>
</reference>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top