An Unremove Tag for Magento Layout XML

Like this article? Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Every so often a theme developer will ask if it’s possible to use the local.xml layout file to reverse the effects of a <remove /> tag.

Unfortunately, this isn’t possible out of the box with Magento. Once a block has been removed there’s no layout XML command that will restore its output.

Fortunately, Magento’s layout system includes the right event hooks to allow you to implement this functionality yourself, so I’ve gone ahead and created a simple Layout Unremove extension. The new extension is pending release on Magento Connect, and I’ve made the package available here as well. The Layout Undelete extension is released under an MIT open source license, which makes it free to use and incorporate in your own projects.

Usage

Usage of the tag is simple, and similar to the delete tag itself. In your local.xml, simply add the following to any handle where you wish to reverse the effects of a removal

<your_handle_name>
    <x-unremove name="left" />
</your_handle_name>

The tag name to use is <x-unremove name="left />. The name attribute should be the name of the block that has been previously removed. I’ve also recorded a quick screencast which covers basic usage. You’ll want to click the “full-size” button to see what’s going on in the video.

Caveats

This isn’t a magical panacea, it’s an experiment. Most existing themes will have removed a section from the layout for a reason, and adding it back in without making appropriate CSS and layout adjustments may result in undesired layout effects.

That said, I hope you find it useful and I welcome any feedback you may have. I’d love to hear if you’re using it in a free or commercial theme.

Like this article? Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Originally published January 3, 2011
blog comments powered by Disqus