Claudio Ferraro
Claudio Ferraro

Reputation: 4721

How to replace a block on the whole site. Magento

I created my custom block which should replace an existing Magento block. Wanna to replace the existing Magento block with my block on the whole site, independetly upon the page and the place where the existing Magento block exists. What should be the reference ? Actually I have something like this:

<default>
<reference name="left">
    <remove name="left.newsletter" />
        <block type="newsletter/subscribe" name="newsletter" after="-" template="mynewsletter/subscribe.phtml"/>
</reference>
</default>

I remove there the default newsletter on the left and then create my newsletter block. It works but replaces only the newsletter block on the left. Wanna to use my block on the whole site in place of left.newsletter even if the block is in other references like content or right etc. What should I do ?

Upvotes: 0

Views: 185

Answers (1)

Fabian Schmengler
Fabian Schmengler

Reputation: 24551

If you want to replace every occurance of Mage_Newsletter_Block_Subscribe with your own block My_Module_Block_Subscribe, use a class rewrite. In your modules config.xml:

<global>
    <blocks>
        <newsletter>
            <rewrite>
                <subscribe>My_Module_Block_Subscribe</subscribe>
            </rewrite>
        </newsletter>
    </block>
</global>

But judging by your code, you actually do not have a custom block, just a custom template. You could change the template with an observer for the core_block_tohtml_before event, that calls setTemplate('mynewsletter/subscribe.phtml') on the block if its class is Mage_Newsletter_Block_Subscribe.

Upvotes: 2

Related Questions