Ben Waine
Ben Waine

Reputation: 1648

How do I override Magento core blocks?

I'm trying to override the Magento review system and use my own instead.

I've created a module and activated it (viewable in the config area of the site). I've created a custom layout and I'm now attempting to override some of the blocks.

I've tried two approaches:

<review_product_list translate="label">

    <block type="reviewwidget/widget" name="product.info.product_additional_data" as="product_additional_data" template="reviewwidget/widget.phtml"></block> 

</review_product_list>

And

<review_product_list translate="label">

    <reference name="content">
        <block type="reviewwidget/widget" name="product.info.product_additional_data" as="product_additional_data" template="reviewwidget/widget.phtml"></block> 
    </reference>   

</review_product_list>

I expected the first approach to override the block and use my custom block and template. It has no effect.

The second approach renders the cotent in my custom template after the block I'm trying to replace.

Can anyone show me how to replace this block?

Upvotes: 2

Views: 1577

Answers (2)

Igor S
Igor S

Reputation: 1895

<blocks>
    <my_module>
        <class>My_Module_Block</class>
    </my_module>
    <review>
        <rewrite>
            <product_view_list>My_Module_Block_Widget</product_view_list>
        </rewrite>
    </review>
</blocks>

Tag <product_view_list> means that you want to rewrite Mage_Review_Block_Product_View_List.

Upvotes: 6

Joe
Joe

Reputation: 1340

Try this:

<reference name="product.info">
    <action method="unsetChild"><alias>product_additional_data</alias></action>
    <!-- add your block here -->
</reference>

Upvotes: 1

Related Questions