Search code examples
magentomagento-1.7magento-layout-xml

Passing a Helper Class a Parameter Through a Layout XML File


I have a working link being added to the top.links block like this:

<block type="page/template_links" name="top.links" as="topLinks">
    <action method="addLink">
        <label>About Us</label>
        <url helper="mymodule/getAboutUsUrl"/>
        <title>About Us</title>
        <prepare/>
        <urlParams/>
        <position>20</position>
    </action>
</block>

Eventually I wanted getAboutUsUrl to turn into getExternalSiteUrl. I want that one function to take parameters. For instance, getExternalSiteUrl('about-us') which would then return something like /the/url/about-us. However, I can't seem to find a way to send a helper class parameters in a Layout XML file. I searched for other modules doing this already, and couldn't find one in the Customer module where I searched.

Can anyone help?


Solution

  • <block type="page/template_links" name="top.links" as="topLinks">
        <action method="addLink">
            <label>About Us</label>
            <url helper="mymodule/getAboutUsUrl">
                <arg>Now with more args!</arg>
                <!-- will result in the string being passed as first arg -->
            </url>
            <title>About Us</title>
            <prepare/>
            <urlParams/>
            <position>20</position>
        </action>
    </block>
    

    Note that helpers do not extend Varien_Object, therefore your method will need to explicitly define the getAboutUsUrl() method.