Magento Tips & Tricks

Adding element with text to system configuration of Magento

System configuration in magento is the heart of your store. You can setup almost any aspect of website in configuration. This is also a place to store configuration settings of your extension. This article show how to add element with text.

You can use this element to add help section or insert information about your company.

Configuration element with text in magento

Configuration section / groups defined in app/code/community/[Company]/[Extension]/etc/system.xml. Lets assume that you already created system.xml. Now we will define new group and insert element with text in it.

<about translate="label">
	<label>NWDthemes.com</label>
	<frontend_type>text</frontend_type>
	<sort_order>0</sort_order>
	<show_in_default>1</show_in_default>
	<show_in_website>1</show_in_website>
	<show_in_store>1</show_in_store>
	<fields>
		<info translate="label">
			<frontend_model>nwdthemes/adminhtml_system_config_info</frontend_model>
			<sort_order>1</sort_order>
			<show_in_default>1</show_in_default>
			<show_in_website>1</show_in_website>
			<show_in_store>1</show_in_store>
		</info>
	</fields>
</about>

As you can see we define custom frontend model in frontend_model tag. It is used to render element.
Renderer class should be stored in
app/code/community/[Company]/[Extension]/Block/Adminhtml/System/Config/Info.php.

<?php

class Nwdthemes_Nwdthemes_Block_Adminhtml_System_Config_Info
    extends Mage_Adminhtml_Block_Abstract
    implements Varien_Data_Form_Element_Renderer_Interface
{

    /**
     * Render Information element
     *
     * @param Varien_Data_Form_Element_Abstract $element
     * @return string
     */
    public function render(Varien_Data_Form_Element_Abstract $element)
    {
        $html = 'Your text / html comes here.';
        return $html;
    }
}

That’s it. If you want to expand this section by default check this article

Leave a Reply

Your email address will not be published. Required fields are marked *