How to disable a remove statement from local.xml in Magento
Is it possible to disable a <remove name="left">
statement defined in a default layout .xml file, from the local.xml file?
For example, in the checkout.xml in the <checkout_cart_index>
section, the statement <remove name="left"/>
is defined there, but can you disable that line from th开发者_C百科e local.xml file, so you still see the left menu on the checkout page?
By default Magento doesn't provide an <unremove />
tag for local.xml. However, the Layout system contains the right events, such that you can implement this yourself. And by "yourself", I mean I've created an experimental extension that adds such a tag. Feedback is welcome.
The two ways I do this are;
Use Alan Storm's excellent unremove plugin above.
Re insert the removed block in local.xml with a new name attribute but the same alias or 'as' attribute.
The name attribute needs to be different because Magento's <remove name="foo" />
is global - it removes all instances of <block name="foo" />
even if they are added after the remove instruction. To re add the left column, for example;
<reference name="root">
<block name="left.2" as="left" type="core/text_list">
<!-- New left column is empty, so you'll need to add your left-column blocks into it here. -->
</block>
</reference>
name="left.2" means the remove action won't kill this block, as="left" means that it will still be inserted into your template via <?php echo $this->getChildHtml('left') ?>
.
Unfortunately, your newly inserted left column is empty. So you'd have to re insert any blocks in there that you want to show as well. Making Alan Storm's plugin all the more useful, I think.
When a block is removed it is not destroyed, only ignored. You might be able to 're-enable' it with:
<checkout_cart_index>
<reference name="root">
<action method="append"><block>left</block></action>
</reference>
</checkout_cart_index>
I've never used this myself and wouldn't want to, if you are making a custom theme then copy the base layout files and edit them directly just as the other answers recommend.
your answer is not to disable the removal but to add it again in your local.xml
Rather than trying to reconstruct the entire set of blocks, comment the remove inside the original XML. This will be less of a maintenance headache than trying to reconstruct the blocks and worrying about precedence of the XML files, etc.
Turn this
<remove name="left" />
Into
<!-- disabling remove because X -->
<!-- <remove name="left" /> -->
精彩评论