Magento – Use a helper in a layout

helperlayoutmagento-1

I want to call a helper in the main layout of my website.

I added this within the part of the layout :

<action method="addLink" translate="label title">
    <label>About us</label>
    <url helper="myModule/getAboutUsUrl" />
    <title>About us</title> 
</action>

And defined my module in the /etc/config.xml this way :

<helpers>
    <myModule>
        <class>My_Module_Helper</class>
    </myModule>
</helpers>

I created my helper My_Module_Helper_Data at the root of includes/src/.

There is no error raised, but it seems that it doesn't work. Any ideas ?

Best Answer

Why are you putting helper file under include/src folder? It should be under your module Helper folder.

Have you enabled compilation mode? If yes then disable that first.

Make a helper class under your module folder and that position should be: YourModuleNameSpace/ModuleName/Helper/Data.php

Class name should be: YourModuleNameSpace_ModuleName_Helper_Data

Then write your function under this class.

Related Topic