How to create custom helper in Magento 2

First of all, you need to create new custom module with following required files before you add custom helper class.

  1. etc/module.xml
  2. registration.php
  3. composer.json (optional)

Lets start to create module for helper class with required files.

create the app/code/Mageclues/Custom/etc/module.xml file

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
	<module name="Mageclues_Custom" setup_version="1.0.0">

Then, create the app/code/Mageclues/Custom/registration.php file.


Then, create the app/code/Mageclues/Custom/composer.json file.

   "name": "mageclues/module-custom",
   "description": "",
   "require": {
       "php": "~5.5.0|~5.6.0|~7.0.0",
       "magento/framework": "100.0.*",
       "magento/module-ui": "100.0.*",
       "magento/module-config": "100.0.*",
       "magento/module-directory": "100.0.*"
   "type": "magento2-module",
   "version": "100.0.0",
   "license": [
   "autoload": {
       "files": [ "registration.php" ],
       "psr-4": {
           "Mageclues\\Custom\\": ""

Finally, we create custom helper class in Magento2. Please create app/code/Mageclues/Custom/Helper/Data.php file.

namespace Mageclues\Custom\Helper;

use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\Helper\AbstractHelper;

class Data extends AbstractHelper

public function __construct(
        Context $context
    ) {

Related Posts

Leave a Reply

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