Magento-1.9 – Get Store Configuration Value in layout.xml File

configurationlayoutmagento-1.9

I have created a module in which I have some setting in admin panel for layout.

My layout.xml code (in this I have added link in top links):

<reference name="top.links">
            <action method="addLink" translate="label title" ifconfig="mbyte/mbyte_links/map_header">
                <label>Store locator</label>
                <url>storelocator/index/index</url>
                <title>Store Locator</title>
                <prepare>true</prepare>
                <position>2</position>
        </action>

Like I have added ifconfig="mbyte/mbyte_links/map_header" in action to check weather it is enable or not in configuration setting.

I have also one more configuration setting for <title>. Now my question starts

Is this possible to get configuration value which I have set in admin panel and directly set here in layout file, if yes what is the procedure to do this?

Thanks in advance!

Best Answer

You can use helpers to retrieve system values required by layout action params.

Create a helper in your module
app/code/local/Mbyte/Links/Helper/Data.php

<?php
class Mbyte_Links_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function getTitleFromConfig()
    {
        return Mage::getStoreConfig('mbyte/mbyte_links/title');
    }
}

Then in your layout.xml you can use

<reference name="top.links">
        <action method="addLink" translate="label title" ifconfig="mbyte/mbyte_links/map_header">
            <label helper="mbyte/data/getTitleFromConfig" />
            <url>storelocator/index/index</url>
            <title helper="mbyte/data/getTitleFromConfig"/>
            <prepare>true</prepare>
            <position>2</position>
    </action>
Related Topic