Sunday, January 15, 2012

Magento How to Remove the Block through XML

Basically there are two ways to remove blocks in layout XML:
by using: <remove name="" />
by using: <action method="unsetChild">

Both are important to understand
<remove name="" /> will operate on a global context, after all the layouts are processed which means that it will remove the named layout block completely, regardless of which layout handle added it.

<action method="unsetChild"> operates on a localized context, specifically, in the context where you use it. So, if you want to remove a specific block from a specific layout handle and possibly insert it at another position or layout handle, you need to use this approach.

Let us understand with example
Use remove
<default>
    <!-- remove the language and store switcher and footer links blocks, we won't use them -->
    <remove name="top.menu" />
    <remove name="footer_links" />
</default>

Use unsetChild to move or rearrange blocks in your layout:
    <default>
        <!-- move the breadcrumb block from the top.bar child block back to the template root -->
        <reference name="top.bar">
            <action method="unsetChild"><name>breadcrumbs</name></action>
        </reference>

        <reference name="root">
            <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
        </reference>
    </default>

No comments:

Post a Comment

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...