1

I try to overwrite a template file with another one which I provide with my extension.

I also noticed that other action methods are working just fine, e.g. <action method='addLink'... successfully adds a link, but <action method='setTemplate'... does not work.

I want to overwrite the template file app\design\frontend\venedor\customdesign\template\page\template\top_links.phtml with app\design\frontend\base\default\template\recaptcha\page\template\top_links.phtml.

app\etc\modules\Magecomp_Recaptcha.xml

<config>
    <modules>
        <Magecomp_Recaptcha>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Page />
            </depends>
        </Magecomp_Recaptcha>
    </modules>
</config>

config.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Magecomp_Recaptcha>
            <version>2.0.8</version>
        </Magecomp_Recaptcha>
    </modules>
    ...
    <frontend>
        <layout>
            <updates>
                <recaptcha>
                    <file>recaptcha.xml</file>
                </recaptcha>                                        
            </updates>
        </layout>
    </frontend>
    ...

I found the following layout conditions in:

app\design\frontend\venedor\customdesign\layout\local.xml

<default>
    ...

    <reference name="top.links">
        <action method="setTemplate">
            <template>page/template/top_links.phtml</template>
        </action>

        <block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/mini_toplinks.phtml" before="-">
            <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
            <block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
                <label>Shopping Cart Sidebar Extra Actions</label>
            </block>
        </block>
    </reference>

So I copied these conditions to the layout file of my extension and changed the template instruction:

app\design\frontend\base\default\layout\recaptcha.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>      
        <reference name="top.links">
            <!-- setTemplate does not work -->
            <action method="setTemplate">
                <template>recaptcha/page/template/top_links.phtml</template>
            </action>

            <!-- addLink works -->
            <action method="addLink" module="recaptcha">
                <label>Google</label>
                <title>Google</title>
                <url>www.google.de</url>
            </action>
        </reference>
    ...

But the old template is still getting loaded instead of the one which I provide through my extension.

I already cleared the cache. There are no infos in the logfiles about this.

UPDATE:

I noticed that my own layout instruction which overwrites top.links is only loaded, if I comment out the instructions in the original layout file. So it must be a precedence thing.

Magento prefers to load app\design\frontend\venedor\customDesign\layout\local.xml instead of the layout file from an extension, even if I put my template files in app\design\frontend\venedor\customDesign\template\recaptcha\... instead of app\design\frontend\base\default\template\recaptcha\...

Please advice.

1

Try to depend on the Mage_Page module in app/etc/Vendor_Module.xml to load your module after the original one:

<?xml version="1.0"?>
[...]
<codePool>local</codePool>
<depends>
    <Mage_Page />
</depends>
[...]
  • There is no file app/etc/Vendor_Module.xml. But I added it to my extension (Magecomp_Recaptcha), see my updated question. It made no difference. Cache cleared already. – Black Oct 9 '18 at 12:01
0

First I explain why it does not work, then at the end I will show how to do it right.

Why is the setTemplate instruction in the layout file ignored?

Apparently it is not possible and not wanted from the magento devs to replace one template with another via layout files. If it has already been set in the layout file of the main design. The layout file of the main design has priority over a layout update file from a extension.

I found the answere here.

"You shouldn't (although I'll give you some possible ideas at the end of this post). Magento is designed such that code in local.xml "wins" over code in an installable module file. The basic idea is local.xml is where a store owner goes to add layout updates that override module file updates. This is How The System Works™ and changing it would create more chaos than it would solve.

That said, you might be able to work within the system if you put your code in a different layout handle. Handles are the node that surround the layout updates

<default>
    ...   
</default>

<catalog_category_view>
</catalog_category_view>

<customer_logged_out>
</customer_logged_out>

etc...

The way Magento's layout system works is all the updates in the default tag are run from module files, and then from local.xml. Then all the updates from catalog_category_view are run from module files, and then from local.xml. Then all the updates from customer_logged_out are run from module files, and then from local.xml.

That is, there's a handle order/specificity. Checkout the Layout tab of the Commerce Bug Demo store (after clicking debug) to see the handle order for a page. (disclaimer: Commerce Bug is a product I created and sell)

So, if your local.xml file applied its updates in default and you really can't rejigger this, then you could apply your module updates in a handle that came later.

Good luck."


You have to overwrite it by overwriting the block class and set the template!

Example:

In this example I show how to replace the template /catalog/product/edit/options/type/text.phtml with my own which is in wr/catalog/product/edit/options/type/text.phtml

app/code/local/WR/EPO/etc/config.xml

<?xml version="1.0"?>

<config>
    <modules>
        <WR_EPO>
            <version>1.0.0.7</version>
        </WR_EPO>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <catalog_product_edit_tab_options_type_text>
                        WR_EPO_Block_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Text
                    </catalog_product_edit_tab_options_type_text>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
...

app\code\local\WR\EPO\Block\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Type\Text.php

class WR_EPO_Block_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Text extends
    Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Text
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('wr/catalog/product/edit/options/type/text.phtml');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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