{"id":94,"date":"2019-03-23T08:23:28","date_gmt":"2019-03-23T08:23:28","guid":{"rendered":"https:\/\/www.magetop.com\/blog\/?p=94"},"modified":"2021-07-26T08:11:53","modified_gmt":"2021-07-26T08:11:53","slug":"how-to-create-new-custom-module-in-magento-2","status":"publish","type":"post","link":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/","title":{"rendered":"How To Create New Custom Module in Magento 2"},"content":{"rendered":"\n<p>In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.<\/p>\n\n\n\n<p>We\u2019re going to build a very simple module in Magento 2. When finished, the module\u2019s output will say \u201cHello world!\u201d in the block content on a custom frontend route.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating the module files and folders<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\">Module setup<\/h5>\n\n\n\n<p>In Magento 2, there are no more code pools. Modules are grouped by namespace and placed directly in the <em>app\/code<\/em>&nbsp;folder.<\/p>\n\n\n\n<p>So our first step is to create the module folder and necessary files required to register a Magento module.<\/p>\n\n\n\n<p>1. Create the following folders:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><em>app\/code\/Magetop<\/em><\/li><li><em>app\/code\/Magetop\/Helloworld<\/em><\/li><\/ul>\n\n\n\n<p>The Magetop folder is the module\u2019s <strong>namespace<\/strong>, and Helloworld is the module\u2019s&nbsp;<strong>name<\/strong>.<\/p>\n\n\n\n<p>Note: If you don\u2019t have the&nbsp;<em>code<\/em>&nbsp;folder in your&nbsp;<em>app<\/em>&nbsp;directory, create it manually.<\/p>\n\n\n\n<p>2. Now that we have a module folder, we need to create a&nbsp;<strong>module.xml<\/strong>&nbsp;file in the&nbsp;<em>app\/code\/Magetop\/Helloworld\/etc<\/em>&nbsp;folder with the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; auto-links: false; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot;?&gt;\n \n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Module\/etc\/module.xsd&quot;&gt;\n    &lt;module name=&quot;Magetop_Helloworld&quot; setup_version=&quot;1.0.0&quot;&gt;\n    &lt;\/module&gt;\n&lt;\/config&gt;\n<\/pre><\/div>\n\n\n<p> 3. To register the module, create a&nbsp;<strong>registration.php<\/strong>&nbsp;file in the&nbsp;<em>app\/code\/Magetop\/Helloworld<\/em>folder with the following code: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    'Magetop_Helloworld',\n    __DIR__\n);\n<\/pre><\/div>\n\n\n<p>4. Open your terminal and go to the Magento 2 root. Run from there the following command: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nphp bin\/magento setup:upgrade\n<\/pre><\/div>\n\n\n<p>If you want to make sure that the module is installed, you can go to Admin \u2192 Stores \u2192 Configuration \u2192 Advanced \u2192 Advanced and check that the module is present in the list or you can open app\/etc\/config.php and check the array for the \u2018Magetop_Helloworld\u2019 key, whose value should be set to 1. <\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Creating a controller<\/h5>\n\n\n\n<p>1. First we need to define the router. To do this, create a&nbsp;<strong>routes.xml<\/strong>&nbsp;file in the&nbsp;<em>app\/code\/Magetop\/Helloworld\/etc\/frontend<\/em>&nbsp;folder with the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; auto-links: false; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:App\/etc\/routes.xsd&quot;&gt;\n    &lt;router id=&quot;standard&quot;&gt;\n        &lt;route id=&quot;helloworld&quot; frontName=&quot;helloworld&quot;&gt;\n            &lt;module name=&quot;Magetop_Helloworld&quot; \/&gt;\n        &lt;\/route&gt;\n    &lt;\/router&gt;\n&lt;\/config&gt;\n<\/pre><\/div>\n\n\n<p>Here we\u2019re defining our frontend router and route with an id \u201chelloworld\u201d.<\/p>\n\n\n\n<p>The&nbsp;<strong>frontName<\/strong>&nbsp;attribute is going to be the first part of our URL.<\/p>\n\n\n\n<p>In Magento 2 URL\u2019s are constructed this way:<br>&lt;frontName&gt;\/&lt;controler_folder_name&gt;\/&lt;controller_class_name&gt;<\/p>\n\n\n\n<p>So in our example, the final URL will look like this:<\/p>\n\n\n\n<p><em>helloworld\/index\/index<\/em><\/p>\n\n\n\n<p>2. Now we create the&nbsp;<strong>Index.php<\/strong>&nbsp;controller file in the&nbsp;<em>app\/code\/Magetop\/Helloworld\/Controller\/Index<\/em>&nbsp;folder with the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; auto-links: false; title: ; notranslate\" title=\"\">\n&lt;?php\nnamespace Magetop\\Helloworld\\Controller\\Index;\n \nuse Magento\\Framework\\App\\Action\\Context;\n \nclass Index extends \\Magento\\Framework\\App\\Action\\Action\n{\n    protected $_resultPageFactory;\n \n    public function __construct(Context $context, \\Magento\\Framework\\View\\Result\\PageFactory $resultPageFactory)\n    {\n        $this-&gt;_resultPageFactory = $resultPageFactory;\n        parent::__construct($context);\n    }\n \n    public function execute()\n    {\n        $resultPage = $this-&gt;_resultPageFactory-&gt;create();\n        return $resultPage;\n    }\n}\n<\/pre><\/div>\n\n\n<p>In Magento 1 each controller can have multiple actions, but in Magento 2 this is not the case. In Magento 2 every action has its own class which implements the execute() method.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Creating a block<\/h5>\n\n\n\n<p>We\u2019ll create a simple block class with the getHelloWorldTxt() method which returns the \u201cHello world\u201d string.<\/p>\n\n\n\n<p>1. Create a&nbsp;<strong>Helloworld.php<\/strong>&nbsp;file in the&nbsp;<em>app\/code\/Magetop\/Helloworld\/Block<\/em>&nbsp;folder with the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; auto-links: false; title: ; notranslate\" title=\"\">\n&lt;?php\nnamespace Magetop\\Helloworld\\Block;\n \nclass Helloworld extends \\Magento\\Framework\\View\\Element\\Template\n{\n    public function getHelloWorldTxt()\n    {\n        return 'Hello world!';\n    }\n}\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\">Creating a layout and template files<\/h5>\n\n\n\n<p>In Magento 2, layout files and templates are placed in the view folder inside your module. Inside the view folder, we can have three subfolders:&nbsp;<em>adminhtml<\/em>,&nbsp;<em>base<\/em>&nbsp;and&nbsp;<em>frontend<\/em>.<br>The adminhtml folder is used for admin, the frontend folder is used for frontend and the base folder is used for both, admin and frontend files.<\/p>\n\n\n\n<p>1. First we will create a&nbsp;<strong>helloworld_index_index.xml<\/strong>&nbsp;file in the&nbsp;<em>app\/code\/Magetop\/Helloworld\/view\/frontend\/layout<\/em>&nbsp;folder with the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; auto-links: false; title: ; notranslate\" title=\"\">\n&lt;page xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;..\/..\/..\/..\/..\/..\/..\/lib\/internal\/Magento\/Framework\/View\/Layout\/etc\/page_configuration.xsd&quot; layout=&quot;1column&quot;&gt;\n    &lt;body&gt;\n        &lt;referenceContainer name=&quot;content&quot;&gt;\n            &lt;block class=&quot;Magetop\\Helloworld\\Block\\Helloworld&quot; name=&quot;helloworld&quot; template=&quot;helloworld.phtml&quot; \/&gt;\n        &lt;\/referenceContainer&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;\n<\/pre><\/div>\n\n\n<p>Every page has a layout hand and for our controller action the layout handle is&nbsp;<strong>helloworld_index_index<\/strong>. You can create a layout configuration file for every layout handle.<\/p>\n\n\n\n<p>In our layout file we have added a block to the content container and set the template<br>of our block to helloworld.phtml, which we will create in the next step.<\/p>\n\n\n\n<p>2. Create a&nbsp;<strong>helloworld.phtml<\/strong>&nbsp;file in the&nbsp;<em>app\/code\/Magetop\/Helloworld\/view\/frontend\/templates<\/em>folder with the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&lt;h1&gt;&lt;?php echo $this-&gt;getHelloWorldTxt(); ?&gt;&lt;\/h1&gt;\n<\/pre><\/div>\n\n\n<p><strong>$this<\/strong>&nbsp;variable is refrencing our block class and we are calling the method getHelloWorldTxt() which is returning the string \u2018Hello world!\u2019.<\/p>\n\n\n\n<p>And that\u2019s it. Open the&nbsp;<em>\/helloworld\/index\/index<\/em>&nbsp;URL in your browser and you should get something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1340\" height=\"713\" data-attachment-id=\"95\" data-permalink=\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/image-13\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?fit=1340%2C713&amp;ssl=1\" data-orig-size=\"1340,713\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?fit=300%2C160&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?fit=800%2C426&amp;ssl=1\" src=\"https:\/\/i2.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?fit=1024%2C545&amp;ssl=1\" alt=\"demo create a new custom module in magento 2\" class=\"wp-image-95\" srcset=\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?w=1340&amp;ssl=1 1340w, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?resize=300%2C160&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?resize=768%2C409&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/image-12.png?resize=1024%2C545&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>It comes to the end of the tutorials: <strong>How To Create New Custom Module in Magento 2<\/strong><\/p>\n\n\n\n<p>We hope this is useful blog for you.<\/p>\n\n\n\n<p>You can read the articles <a href=\"https:\/\/www.magetop.com\/blog\/magento-2-how-to-create-database-table\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Create Database Table in Magento 2<\/a>.<\/p>\n\n\n\n<p>Thank you for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.<br \/>\nWe\u2019re going to build a very simple module in Magento 2. When finished, the module\u2019s output will say \u201cHello world!\u201d in the block content on a custom frontend route.<\/p>\n","protected":false},"author":1,"featured_media":105,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[42,43,44,27],"class_list":["post-94","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento-2-tutorials","tag-how-to-create-new-custom-module","tag-how-to-create-new-custon-module-in-magento-2","tag-magento-2-create-custom-module","tag-magento-2-knowledge"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Create New Custom Module in Magento 2 - Magetop Blog<\/title>\n<meta name=\"description\" content=\"In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Create New Custom Module in Magento 2 - Magetop Blog\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Magetop Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/MagetopStore\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/MagetopStore\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-23T08:23:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-26T08:11:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"679\" \/>\n\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Adam Roger\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/MagetopStore\" \/>\n<meta name=\"twitter:site\" content=\"@MagetopStore\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Adam Roger\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/\"},\"author\":{\"name\":\"Adam Roger\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411\"},\"headline\":\"How To Create New Custom Module in Magento 2\",\"datePublished\":\"2019-03-23T08:23:28+00:00\",\"dateModified\":\"2021-07-26T08:11:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/\"},\"wordCount\":732,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1\",\"keywords\":[\"how to create new custom module\",\"how to create new custon module in magento 2\",\"magento 2 create custom module\",\"magento 2 knowledge\"],\"articleSection\":[\"Magento 2 Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/\",\"url\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/\",\"name\":\"How To Create New Custom Module in Magento 2 - Magetop Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1\",\"datePublished\":\"2019-03-23T08:23:28+00:00\",\"dateModified\":\"2021-07-26T08:11:53+00:00\",\"description\":\"In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1\",\"width\":679,\"height\":360,\"caption\":\"how to create new custom module in magento 2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.magetop.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Create New Custom Module in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#website\",\"url\":\"https:\/\/www.magetop.com\/blog\/\",\"name\":\"Magetop Blog\",\"description\":\"Exploring Magento Tips, Tricks, and Trends\",\"publisher\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.magetop.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#organization\",\"name\":\"Magetop.com\",\"url\":\"https:\/\/www.magetop.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1\",\"width\":475,\"height\":475,\"caption\":\"Magetop.com\"},\"image\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/MagetopStore\",\"https:\/\/x.com\/MagetopStore\",\"https:\/\/www.linkedin.com\/company\/magetop\",\"https:\/\/www.pinterest.com\/magetop\",\"https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411\",\"name\":\"Adam Roger\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g\",\"caption\":\"Adam Roger\"},\"description\":\"CEO and Founder of Magetop. A friend, a husband and a dad of two children. Adam loves to travel to experience new cultures and discover what is happening with ecommerce all around the world.\",\"sameAs\":[\"https:\/\/www.magetop.com\",\"https:\/\/www.facebook.com\/MagetopStore\",\"https:\/\/www.instagram.com\/magetopstore\",\"https:\/\/www.linkedin.com\/company\/magetop\",\"https:\/\/www.pinterest.com\/magetop\",\"https:\/\/x.com\/https:\/\/twitter.com\/MagetopStore\",\"https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA\",\"https:\/\/magetop.tumblr.com\"],\"url\":\"https:\/\/www.magetop.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Create New Custom Module in Magento 2 - Magetop Blog","description":"In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"How To Create New Custom Module in Magento 2 - Magetop Blog","og_description":"In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.","og_url":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/","og_site_name":"Magetop Blog","article_publisher":"https:\/\/www.facebook.com\/MagetopStore","article_author":"https:\/\/www.facebook.com\/MagetopStore","article_published_time":"2019-03-23T08:23:28+00:00","article_modified_time":"2021-07-26T08:11:53+00:00","og_image":[{"width":679,"height":360,"url":"https:\/\/i1.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1","type":"image\/png"}],"author":"Adam Roger","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/MagetopStore","twitter_site":"@MagetopStore","twitter_misc":{"Written by":"Adam Roger","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/"},"author":{"name":"Adam Roger","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411"},"headline":"How To Create New Custom Module in Magento 2","datePublished":"2019-03-23T08:23:28+00:00","dateModified":"2021-07-26T08:11:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/"},"wordCount":732,"commentCount":0,"publisher":{"@id":"https:\/\/www.magetop.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1","keywords":["how to create new custom module","how to create new custon module in magento 2","magento 2 create custom module","magento 2 knowledge"],"articleSection":["Magento 2 Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/","url":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/","name":"How To Create New Custom Module in Magento 2 - Magetop Blog","isPartOf":{"@id":"https:\/\/www.magetop.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1","datePublished":"2019-03-23T08:23:28+00:00","dateModified":"2021-07-26T08:11:53+00:00","description":"In this tutorial, we will teach you how to create new custom module in Magento 2 to add customized functionality and give you more control over the store.","breadcrumb":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#primaryimage","url":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1","width":679,"height":360,"caption":"how to create new custom module in magento 2"},{"@type":"BreadcrumbList","@id":"https:\/\/www.magetop.com\/blog\/how-to-create-new-custom-module-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.magetop.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Create New Custom Module in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/www.magetop.com\/blog\/#website","url":"https:\/\/www.magetop.com\/blog\/","name":"Magetop Blog","description":"Exploring Magento Tips, Tricks, and Trends","publisher":{"@id":"https:\/\/www.magetop.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.magetop.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.magetop.com\/blog\/#organization","name":"Magetop.com","url":"https:\/\/www.magetop.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1","width":475,"height":475,"caption":"Magetop.com"},"image":{"@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/MagetopStore","https:\/\/x.com\/MagetopStore","https:\/\/www.linkedin.com\/company\/magetop","https:\/\/www.pinterest.com\/magetop","https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA"]},{"@type":"Person","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411","name":"Adam Roger","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g","caption":"Adam Roger"},"description":"CEO and Founder of Magetop. A friend, a husband and a dad of two children. Adam loves to travel to experience new cultures and discover what is happening with ecommerce all around the world.","sameAs":["https:\/\/www.magetop.com","https:\/\/www.facebook.com\/MagetopStore","https:\/\/www.instagram.com\/magetopstore","https:\/\/www.linkedin.com\/company\/magetop","https:\/\/www.pinterest.com\/magetop","https:\/\/x.com\/https:\/\/twitter.com\/MagetopStore","https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA","https:\/\/magetop.tumblr.com"],"url":"https:\/\/www.magetop.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2019\/03\/create-custom-magento-2-module.png?fit=679%2C360&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/paOdw5-1w","jetpack-related-posts":[{"id":1402,"url":"https:\/\/www.magetop.com\/blog\/magento-2-extension-tutorial\/","url_meta":{"origin":94,"position":0},"title":"Magento 2 Extension Tutorial","author":"Aaron LX","date":"February 15, 2020","format":false,"excerpt":"Magento 2 is an open-source platform that allows you can create a module for yourself. And those modules can extend functions for the Magento store. And in this article, I will introduce to Magento 2 Extension Tutorial.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"Magetop Extension Tutorial","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/02\/Extension-Tutorial.jpg?fit=750%2C455&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/02\/Extension-Tutorial.jpg?fit=750%2C455&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/02\/Extension-Tutorial.jpg?fit=750%2C455&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/02\/Extension-Tutorial.jpg?fit=750%2C455&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1091,"url":"https:\/\/www.magetop.com\/blog\/how-to-create-simple-module-to-configure-options-for-theme-in-magento-2\/","url_meta":{"origin":94,"position":1},"title":"How To Create Simple Module To Configure Options For Theme In Magento 2","author":"Adam Roger","date":"January 4, 2020","format":false,"excerpt":"In this article, we will introduce you to How to create simple module to configure options for theme in Magento 2.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"How To Create Simple Module To Configure Options For Theme","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Create-Simple-Module-To-Configure-Options-For-Theme.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Create-Simple-Module-To-Configure-Options-For-Theme.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Create-Simple-Module-To-Configure-Options-For-Theme.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Create-Simple-Module-To-Configure-Options-For-Theme.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1458,"url":"https:\/\/www.magetop.com\/blog\/magento-2-folder-structure\/","url_meta":{"origin":94,"position":2},"title":"Magento 2 Folder Structure","author":"Aaron LX","date":"March 6, 2020","format":false,"excerpt":"In the first lesson, I want to introduce to you the folder structure of Magento 2 and the function of each of those directories. This is a very important lesson in this series. If you know the functions of each of these folders, it will become easier to absorb the\u2026","rel":"","context":"In &quot;Magento 2 Knowledge Base&quot;","block_context":{"text":"Magento 2 Knowledge Base","link":"https:\/\/www.magetop.com\/blog\/magento-2-knowledge-base\/"},"img":{"alt_text":"Magento 2 Folder Structure","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/03\/Magento-2-Folder-Structure.png?fit=638%2C384&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/03\/Magento-2-Folder-Structure.png?fit=638%2C384&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/03\/Magento-2-Folder-Structure.png?fit=638%2C384&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":8635,"url":"https:\/\/www.magetop.com\/blog\/how-to-override-email-template-in-custom-module-magento-2\/","url_meta":{"origin":94,"position":3},"title":"How to Override Email Templates in Custom Module in Magento 2","author":"Callula Huy","date":"August 24, 2023","format":false,"excerpt":"In this article, I will guide you on how to effectively override email templates in Magento 2 using a custom module.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"How to Override Email Templates in Custom Module in Magento 2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2023\/08\/How-to-Override-Email-Templates-in-Custom-Module-in-Magento-2.png?fit=1200%2C616&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2023\/08\/How-to-Override-Email-Templates-in-Custom-Module-in-Magento-2.png?fit=1200%2C616&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2023\/08\/How-to-Override-Email-Templates-in-Custom-Module-in-Magento-2.png?fit=1200%2C616&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2023\/08\/How-to-Override-Email-Templates-in-Custom-Module-in-Magento-2.png?fit=1200%2C616&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2023\/08\/How-to-Override-Email-Templates-in-Custom-Module-in-Magento-2.png?fit=1200%2C616&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1138,"url":"https:\/\/www.magetop.com\/blog\/add-custom-category-attributes-in-magento-2\/","url_meta":{"origin":94,"position":4},"title":"Add Custom Category Attributes In Magento 2","author":"Adam Roger","date":"January 12, 2020","format":false,"excerpt":"In the previous article, we learned about How to get product collection in Magento 2. Today, we will introduce you about Add custom category attributes in Magento 2. I think you should read How To Create New Theme In Magento 2 first.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"Add Custom Category Attributes In Magento 2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1067,"url":"https:\/\/www.magetop.com\/blog\/customize-cover-illustration-layout-in-magento-2\/","url_meta":{"origin":94,"position":5},"title":"Customize Cover, Illustration Layout In Magento 2","author":"Adam Roger","date":"January 2, 2020","format":false,"excerpt":"Our previous post is How to create new theme in Magento 2. I think you guys should read it. To continue the previous post, we will introduce you to Customize cover, illustration layout in Magento 2.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"Customize Cover, Illustration Layout Magento 2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":10,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":6912,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions\/6912"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/media\/105"}],"wp:attachment":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}