Best practice to add a layout handle for my custom module?
-
12-12-2019 - |
Question
I think I read somewhere that the best place to add a layout handle for a custom module was through the local.xml file in layouts folder. However, almost all modules that I have seen, never has one used the local.xml. Is it the best practice to use local.xml?
Do you have a link to an article explaining this practice? Also, say I just want to add a lone js/css file to the layout on every page, would local.xml's default handle be the best practice to do it OR what is the best approach for it?
Solution
You should declare a layout file in your custom module and then create this file in the layout directory, so in config.xml:
<?xml version="1.0"?>
<config>
...
<frontend>
...
<layout>
<updates>
<yourmodule>
<file>layoutfilename.xml</file>
</yourmodule>
</updates>
</layout>
</frontend>
</config>
And then create the layout file layoutfilename.xml
and inside this declare your layout handles and blocks etc just like any layout file:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
...
<reference name="head">
...
<action method="addItem">
<type>skin_js</type>
<name>js/somejsfile.js</name>
</action>
</reference>
</default>
</layout>