Reputation: 153
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
Upvotes: 0
Views: 1411
Reputation: 153
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.
Upvotes: 1
Reputation: 53
First make sure you are putting it in your theme folder. Second the updates reference the Module Name not its namespace so it would be
<frontend>
<layout>
<updates>
<Sample_Module>
<file>samplemodule.xml</file>
</Sample_Module>
</updates>
</layout>
</frontend>
Then try adding this: <layout version="0.1.0">
instead of layout. Then add this:
<default>
<reference name="head">
<action method="setTitle"><rel>DID THIS WORK??</re></action>
</reference>
</default>
this will set the title of every page.
Other things to check: is the module being loaded?
Upvotes: 0