Is it possible to change a block type in layout XML?

I know how to change template using setTemplate method, but I am trying to change a block's type. Is this possible?

  • please explain in details what you have to change
    – Keyul Shah
    Jan 26, 2014 at 16:58

4 Answers 4


Changing the block type means changing the block class, so no, but...

... you can just overwrite the block:

  1. Find a layout handle which is invoked later OR be sure, that your layout.xml is processed after the block is created, e.g. with <depends> in Company_Module.xml
  2. Just create a new block of other type with the same name

The problem is, that this overwrites the block and does not change the type. This means everything which is done on this block between the creation and your change is lost.

For example for changing the catalog.navigation:

<layout version="0.1.0">
    <catalog_category_default translate="label">
        <reference name="left">
            <block type="myModule/navigation" name="catalog.leftnav" after="currency" template="myModule/catalog/navigation/left.phtml"/>
  • 1
    You can also create a new block class that "inherits" the block class you are looking to replace. You will need to add an entry in the config.xml of your custom extension to swap the block class with yours. This would make sense if you plan to extend or modify the block's functionality. Mar 2, 2016 at 16:50

You can't change it in the layout-files afaik. You can, however, extend and override them in your config-files.



Remember to extend the original block.


I was facing similar issue that I need to update a specific block for a specific layout.

What I end up doing and it seems to work is (in the layout file)

    <reference name="block_name_reference">
        <block type="mymodule/customblock" name="block_name_reference" />

Hope this helps.


If there is a parent block that can be referenced, then you can set the type like this:

    <reference name="product.info">
        <block type="student/course_addtocart" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.