Search code examples
magentomagento-1.9

Magento - Trouble loading module layout xml file


I'm creating a simple sample module in magento 1.9 and I am hoping to do display a custom block on the front end product page - through my module; however I have stumbled in trouble early on.

In my modules config.xml I have defined a front end layout update, below as the full config.xml file

<?xml version="1.0"?>
<config>
    <modules>
        <MP_SampleModule>
            <version>0.0.1</version>
        </MP_SampleModule>
    </modules>

    <frontend>
        <layout>
            <updates>
                <MP_SampleModule>
                    <file>samplemodule.xml</file>
                </MP_SampleModule>
            </updates>
        </layout>
    </frontend>
</config>

I have confirmed the module is loading.

For the layout file, I created samplemodule.xml : \app\design\frontend\rwd\default\layout\samplemodule.xml

rwd is my active theme.

the samplemodule.xml contents are as follows:

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
            <action method="setTitle">
                <rel>DID THIS WORK??</rel>
            </action>
        </reference>
    </default>
</layout>

However it seems Magento is not picking up this file at all. I have tried placing invalid xml in the samplemodule.xml in the hope Magento would throw an error confirming it is at least being loaded, but as no error is thrown I'm lead to believe it is simply being ignored.

I've read countless other similar questions on SO and on other sites but i've hit a brick wall so any insight into the issue would be welcomed and anything leading to a solution would be applauded.

Thanks


Solution

  • After a few days of not making any progress with this, I decided to try again. In the end I changed the contents of my files to the following which seems to have done the trick:

    \app\code\community\MP\SampleModule\etc\config.xml

    <?xml version="1.0"?>
    <config>
        <modules>
            <MP_SampleModule>
                <version>0.0.1</version>
            </MP_SampleModule>
        </modules>
    
        <frontend>
            <layout>
                <updates>
                    <MP_SampleModule module="MP_SampleModule">
                        <file>mp_samplemodule.xml</file>
                    </MP_SampleModule>
                </updates>
            </layout>
        </frontend>
    </config>
    

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

    <?xml version="1.0" encoding="UTF-8"?>
    <layout>
        <default>
            <reference name="before_body_end">
                <block type="core/template"
                   name="test"
                   template="mp/samplemodule/test.phtml"/>
            </reference>
        </default>
    </layout>
    

    This now correctly outputs contents of test.phtml (\app\design\frontend\base\default\template\mp\samplemodule\test.phtml) near the end of the page.

    Thanks for all the insights provided which was helpful in finding the solution.