How To Create Helper

Prerequisities

You need to have a custom module for this. Assuming we have a module with namespace Guides and module name Meta.

Creating a Helper

Helpers are used to help you obviously. Usually you will use them for general functions which you can use everywhere and those functions are not suitable for placing them into a model.

<config>
    <modules>
        <guides_meta>
            <version>1.0.0</version>
        </guides_meta>
    </modules>
    <global>
        <helpers>
            <guides_meta>
                <class>Guides_Meta_Helper</class>
            </guides_meta>
        </helpers>
    </global>
</config>
<?php

class Guides_Meta_Helper_Data extends Mage_Core_Helper_Abstract {

  public function get_content() {
    return 'This is the content from Helper';
  }
}

Now you have to somewhere call our new Helper method. You can do it like this and reuse it anytime you want.

$helper = Mage::helper('guides_meta'); // Assuming that our helper is Data.php, if it had a different name than you have you append _Filename in the end

echo $helper->get_content(); // Calls our defined method

/* output will be: This is the content from Helper */

 

 

 


Lukas
Lukas Stranovsky
I am the guy who made this. Sorry for typos.