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?

Was it helpful?

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top