Vindfrisk
Vindfrisk

Reputation: 69

Override "setTemplate" Magento xml

In my theme I already use (in local.xml):

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

Now I'm making a module where I want to change the template, hence making the module installable without any needs to modify the theme. So almost same code from a module xml-file:

<reference name="top.links">
    <action method="setTemplate"><template>sociallogin/header/links.phtml</template></action>
</reference>

Magento always pick the first one in local.xml How can I override this?

Upvotes: 2

Views: 6027

Answers (2)

Alana Storm
Alana Storm

Reputation: 166066

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.

Upvotes: 5

pspahn
pspahn

Reputation: 2790

Your local.xml layout file will have precedence over all the other xml files (except for the /app/etc/local.xml file, but you should not be using that for layout).

You should remove the declaration from the local.xml file.

Upvotes: 2

Related Questions