Magento – Replace root block in layout

blockslayout

In attempting to avoid rewriting the Mage_Checkout_Block_Onepage_Shipping_Method_Additional block, I've been following my current strategy of removing the block with the old class and adding a new one with my new class:

<checkout_onepage_shippingmethod>
  <remove name="root" />
  <block type="my_checkout/onepage_shipping_method_additional" name="my.root" as="root" output="toHtml" template="checkout/onepage/shipping_method/available.phtml" />
</checkout_onepage_shippingmethod>

This works great for non-root blocks, but my alias technique doesn't seem to work in this case. Any ideas?

PS: I'm aware that this can be done with a rewrite.

Best Answer

I can't believe, this is working.

<remove> is the last statement processed before toHtml. This means, there is NO WAY to have a block with the name root when you remove it.

Bu you can just change the type of root by overriding the block, like in <checkout_onepage_shippingmethod> in /app/design/frontend/base/default/layout/checkout.xml:373

<checkout_onepage_shippingmethod>
    <!-- Mage_Checkout -->
    <remove name="right"/>
    <remove name="left"/>

    <block type="checkout/onepage_shipping_method_available" name="root" output="toHtml" template="checkout/onepage/shipping_method/available.phtml"/>
</checkout_onepage_shippingmethod>

It is totally great, that you avoid rewrites!

Related Topic