How to create a Magento 2 extension

How to create a Magento 2 extension

Yay, Magento 2 is officially out!

Great news indeed. My name is Alex, and I’m a Magento developer at Amasty. For the last few months I’ve been busy building Magento 2 extensions, and today I wanted to share an instruction on building a simple Magento 2 module.

What we’re going to build

To demonstrate how to create a Magento 2 extension, we are going to build a HelloWorld module, which is going to have some basic functionality, covering as many development aspects as possible in this case.

This Magento 2 extension is going to have a model with undefined data, which will be stored in the database. And we’ll display the values on the product page.

What’s more, we are going to create several settings to change the extension’s behavior. Nothing complicated, so let’s start!

Create configuration

The first step is to install Magento 2 and create a catalog to store the extension files. In Magento 2 files are not distributed through the folders and have a modular structure.

The files of the newly created extension will be in this catalog:


Here Amasty is the name of the company that developed the extension, HelloWorld is the name of the Magento 2 extension we are building at the moment.

Now it’s time to actually code the extension. Catalogs purposes have slightly changed in comparison with the first versions of Magento.

Extension configuration is located in etc folder, as before.

Let’s create app\code\Amasty\ HelloWorld \etc catalog and a module.xml file inside it. This is the file where we are going to set our extension name and its version.

The file looks like this:

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Amasty_HelloWorld" setup_version="0.0.0">

Now let’s check if Magento 2 sees the extension.

Run the following console command:

php bin/magento setup:upgrade

But there’s no result. To fix it, let’s create registration.php file in the root folder of the extension and put the following code inside:

 * @author Amasty Team
 * @copyright Copyright (c) 2015 Amasty (
 * @package Amasty_HelloWorld

This is done to tell Magento 2 that it should run the extension from the current directory.

Now go and clear Magento cache, and you’ll see that our extension is working now:

How to create Magento 2 extension: enable module

Create settings

Now let’s create some settings for the new extension. To do that, add adminhtml catalog to etc catalog. It will contain configuration files for backend.

The first file we need here is routes.xml for frontName and id setting, which is used to define queries for the extension. It is done by the following piece of code:

<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="admin">
        <route id="amasty_helloworld" frontName="amasty_helloworld">
            <module name="Amasty_HelloWorld" />

Now let’s configure the extension settings. As in the previous version, they’re located in the system.xml file, but the xml markup is slightly different in Magento 2.

I’m creating the three most popular settings as an example: a text setting, yes/no setting and a setting with custom values.

Have a look at the config file contents and what it actually means:

<?xml version="1.0"?>
<!-- /** * @author Amasty Team * @copyright Copyright (c) 2015 Amasty ( * @package Amasty_HelloWorld */ -->
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd">
        <tab id="amasty" translate="label" sortOrder="10">

<section id="amasty_helloworld" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <field id="enable" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable Hello World</label>
                        Comment for `Enable Hello World` setting.
                <field id="block_label" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Block Label</label>
                <field id="text_align" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Text Align</label>


Add a new section to the settings block using <tab>. Set the unique ID and the name of the settings section inside. It is done because we have a very high possibility of using several apps from the same vendor on a single site.

Add the new <section id=”amasty_helloworld”> , again, with the unique ID, and set the necessary parameters, such as type, translation fields, order, label, the block for which the section is added, and so on. And then add the settings just inside the section. They will be divided into groups (one group in our case). The groups are defined by <group>, and the fields are set by <field>. We have already created three settings and pointed out types, labels, visibility, translation, comments and the data model.

In our case the third setting implies custom data, so we pointed out a separate data model for it. To do that, you need to create Amasty\HelloWorld\Model\Source\ Align model, where we will set the needed choice variants. The extension should be defined from \Magento\Framework\Option\ArrayInterface interface, and you need to redefine toOptionArray() and toArray() methods as well.

To check what you are doing, go to the bottom of the article and subscribe to get the code of the whole extension.

Let’s check the result. Open your Magento 2 backend, go to Stores – Configuration. Boom, we can see the settings!

Create Magento 2 extension: create module settings

Now, as we created the settings, we should set default values for the options. To do that, create a config.xml in the etc catalog and put the default values in accordance with system.xml in there.

Frontend output


Now let’s try to show something on the frontend, i.e. to create a block and a template for it, and then to show this block on the product page.

Create a class of \Amasty\HelloWorld\Block\Catalog\Product\HelloWorld block, which should inherit from Magento class \Magento\Framework\View\Element\Template

We are going to use the parent constructor. Here’s how it will look like for this block:

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = []
) {
    parent::__construct($context, $data);


Let’s create a simple template and put it in the following catalog:


You can see that in Magento 2 we have the view catalog, where we’re going to store the information, which was scattered in several theme catalogs, such as templates, layouts, scripts, styles, before.

Put this simple text inside:

<?=__(‘Hello World’);?>

As we see from the example, now you can perform translation in Magento using __() without a separate class. And the translation for this line will be pulled from Amasty\HelloWorld\i18n\en_US.csv

We have created the template, now let’s show it on the product page.


Time to create the layout! Now we are creating not a unique layout for all the pages, but a separate file for each page. As we will show the block on the product page, let’s create a layout with the following name:
Put this code inside:

<!-- /** * @author Amasty Team * @copyright Copyright (c) 2015 Amasty ( * @package Amasty_HelloWorld */ -->
<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <css src="Amasty_HelloWorld/css/hello.css"/>
        <referenceContainer name="">
            <block name="amasty_helloworld.helloworld" class="Amasty\HelloWorld\Block\Catalog\Product\HelloWorld" before="-" template="product/hello.phtml" />

As an example, we added the new block into block in the layout code and added the styles file to use when showing on frontend. The styles file has the following address:


Refresh the product page:

Create Magento 2 extension: see block on product page

Voila, the block is there!

Now let’s change the look of the block – and add the helper initialization to it.

The extension constructor looks like this:

 * @var \Amasty\HelloWorld\Helper\Data
protected $_helper;

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = [],
    \Amasty\HelloWorld\Helper\Data $helper
) {
    parent::__construct($context, $data);

    $this->_helper = $helper;

The helper from the created block is used as $this->_helper variable.


Create the helper in the following catalog:


Add \Magento\Framework\App\Config\ScopeConfigInterface interface object initialization to the helper, it works to receive the data from configuration.

Now the file looks like this:

<?php /** * @author Amasty Team * @copyright Copyright (c) 2015 Amasty ( * @package Amasty_HelloWorld */ namespace Amasty\HelloWorld\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { /** * @var \Magento\Framework\App\Config\ScopeConfigInterfac */ protected $_scopeConfig; CONST ENABLE = 'amasty_helloworld/general/enable'; CONST BLOCK_LABEL = 'amasty_helloworld/general/block_label'; CONST TEXT_ALIGN = 'amasty_helloworld/general/text_align'; public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig ) { parent::__construct($context); $this->_scopeConfig = $scopeConfig;

    public function getEnable(){
        return $this->_scopeConfig->getValue(self::ENABLE);

    public function getBlockLabel(){
        return $this->_scopeConfig->getValue(self::BLOCK_LABEL);

    public function getTextAlign(){
        return $this->_scopeConfig->getValue(self::TEXT_ALIGN);

In this piece of code you can see that three functions for getting extension configuration from settings section were created.

Let’s use these functions in the block and change the template:

<?php /** * @author Amasty Team * @copyright Copyright (c) 2015 Amasty ( * @package Amasty_HelloWorld */ ?>

<div class="amasty-helloworld-block" style="text-align: <?= $this->getTextAlign()?>">

<h3 class="label"><?= $this->getBlockLabel()?></h3>

    <?=__('Hello World');?>

Now the block is displayed taking the settings into account:

Create Magento 2 extension: block is displayed accroding to settings

Model creation

Create installation script

As in the 1.x versions of Magento, you need to create the installation file to use your own table. We are going to describe creating of a simple table with several fields. The file should be created here: Amasty\HelloWorld\Setup\InstallSchema.php

And this is its contents:

public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    $installer = $setup;

    $table  = $installer->getConnection()
            ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
            ['default' => null, 'nullable' => false],
            ['default' => null, 'nullable' => false],

You can see that we are creating an ‘amasty_helloworld’ table with one field of integer type and two fields of text type.

Model creation

As in the previous Magento version, we need to create three classes to work with the model: the model itself, the resource model and the collection.

Let’s create a Amasty\HelloWorld\Model\HelloWorld.php file and use the following initialization:

 * Copyright © 2015 Amasty. All rights reserved.

namespace Amasty\HelloWorld\Model\ResourceModel;

class HelloWorld extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
     * Model Initialization
     * @return void
    protected function _construct()
        $this->_init('amasty_helloworld', 'id');

We just set the constructor for the model here. In fact, there is no great difference from the first Magento versions on this step. The resource model and the collection are stored in the following catalogs:



These files’ listings are of no particular interest, you can download the extension in the end of the article and see them if needed. Now we are going to check if the created model actually works. Create a simple function in the block we’re working with:

public function getCollection()
    $model = $this->_objectManager->create('Amasty\HelloWorld\Model\HelloWorld');
    $collection = $model->getCollection();

    return $collection;

and display it inside the template:

<?php foreach($this->getCollection() as $item):?>

<label><?= __("Title: ") . $item->getLabel()?></label> -- <label><?= __("Value: ") . $item->getValue();?></label>

<?php endforeach;?>

Now update the product page: it works!

Create Magento 2 extension: final result

Download the example Magento 2 extension for free:

We have successfully created a very simple Magento 2 extension. Remember, if you were following the steps and something is not working, first things first delete all the cache files from the var folder and then try again.
Should you have any questions about this process of Magento 2 extension development, please ask them in comments. Good luck to you!

Alexey Motorny

Alexey Motorny

Alexey makes your stores visually attractive and improves usability. He manages such modules as Colors Swatches Pro, Ajax Shopping Cart, Facebook and Twitter Promo and others. Guitar takes the place of keyboard in his hands during free time.

You may also like...

92 Responses

  1. Nestor González says:

    This is GOLD, thank you very much Alex!

  2. Amit Bera says:

    It is really help full.

    Amit Bera

    • Ksenia Dobreva Ksenia Dobreva says:

      Thanks for reading!

      • santosh says:

        hi ksenia Dobreva,
        Thanks for the precious information.
        can you just help me out in the scenario where a user want to add data from admin panel and it just stores in db and then will fetched and render in frontend,right now i have to put text value and label manually in database….
        Thanks in advance, wishing you a happy new year.

  3. Shopagentur says:

    extension für the shop, that what I’ve searched for. It works! Nice !

  4. Larry Reliford says:

    Good article, with simple training and perfect. Magento is the most important tool to use in e-commerce market.

  5. Kamrul says:

    Thank you Alexey for sharing your knowledge about magento 2 extension. I have learned a lot from this post. Really helpful post for me.

  6. aidalab says:

    great work!!!!! I admire your efforts keep it up.

  7. Carlos says:

    I think that will be great, if you add of ” <?php " at the begin registration.php file .

    I also appreciate if you could put all paths for each file. I new in Magento world, so i'm familiar with.

    First part works for me, then I get lost.

    Thanks for your time and patience.

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey Carlos, thanks for reading and for your suggestions! As for the file paths, you can easily download the extension from git (see the link in the end of the article) and see them for all the files you need. Good luck with your studies!

      • Eres says:

        Come on man, there is no git link in there? Why the hell you waist other people time? I got lost too because you haven’t wrote this tutorial for beginners. and what is this??? “To do that, add adminhtml catalog to etc catalog. ” what the hell is this, who knows what is adminhtml and catalog and where are these located.

        • Eres says:

          I found it. Pardon me. You can delete my comment. :)

          • Eres says:

            The actual source of confusion is the term “Catalog” in this tutorial. You are using the term “Catalog” instead of “Folder”.
            There would have been no problem if you will say ” add adminhtml FOLDER to etc FOLDER” instead of ” add adminhtml catalog to etc catalog”. May be the magento guys use this term for folder?

            • Ksenia Dobreva Ksenia Dobreva says:

              Hi Eres,

              thanks for your notes! We will take these terms into consideration for our next articles. Cheers!

              • mitch says:

                Where??? There is no link to the Git??? Why not just post a link and take 2 more seconds type where to put a file like config.xml and what is “create a config.xml in the etc catalog and put the default values in accordance with system.xml in there”? What does that mean? Please take an extra few seconds to explain things, it’s extremely frustrating… not everyone is coming from Magento 1. Just update the blog please to add this info for people who will visit tomorrow, and the day after and the year after… think ahead a little please.

                • Ksenia Dobreva Ksenia Dobreva says:

                  Hey Mitch, you can easily download the example extension at the end of the article (subscription form) and investigate the structure of the extension in every way!
                  As for your question, the M1 config.xml included various extension configuration settings and also their default values. In M2, it has only default values for options from system.xml. Hope that helps! If you have any other questions, we will be happy to help.

          • Ksenia Dobreva Ksenia Dobreva says:

            I’m glad it finally worked =)

  8. santosh says:

    @alexey first of all thanks to the beautiful article but i just wanted to know, what if i just wanted to set label and value of text through user, right now i have to enter it manual in my database, can you please guide me over this.
    Thanks in advance.

    • Ksenia Dobreva Ksenia Dobreva says:

      Hi there and thanks for your question.

      We didn’t implement a separate page scenario with adding the values to the database. But thanks for your suggestion – we will definitely have this idea in mind when writing the next post about Magento 2 development. Meanwhile, you can go to Magento 2 module creator and see the example implementation of what you’d like to see.

      Hope that helps!

  9. Jine says:

    Hello, thanks for this tutorial. I have a problem with the css file. I can see the file linked in the viewsource and onlclick I also see the css code. But the styles are not being applied to the block on the product page. On inspection with firebug, I don’t see the style file or the class styles either. What am I missing here? Thanks for your time.

    • Ksenia Dobreva Ksenia Dobreva says:

      Hello and thanks for the question!

      Could you please double-check these points?

      1. Please make sure your added your css file to the right xml file
      2. Clear Magento cache

      Let me know if that helps.

  10. Lachezar says:

    Great tutorial! I didn’t understand one thin – how did the “Hello World” message (I should say template, to be more precise) is printed to that exact part of the page – on the specific product’s page under the Product Name element. Thank you for the great tutorial, of if you are a Bulgarian by any chance – Благодаря! :) :) It was very, very helpful.

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey Lachezar,
      we’re happy that the post was useful for you!
      To show the block, we went to catalog_product_view.xml and defined it as

      <block name="amasty_helloworld.helloworld" class="Amasty\HelloWorld\Block\Catalog\Product\HelloWorld" before="-" template="product/hello.phtml" />

      Hope that helps!

      Ha-ha, I’m not a Bulgarian =) It’s my husband’s second name, and, as far as I know, he has some Bulgarian roots =) Thanks again!

  11. Volodymyr says:

    After “bin/magento setup:upgrade” all pages are blank (front, admin).
    Command “setup:di:compile” not resolve problem

  12. Vikram says:

    Followed the above blog. But my helper function is called only by using `$this->helper(‘Namespace\Modulename\Helper\Data’)->getModuleStatus()` and not as shown in code above `$this->getModuleStatus()`. Why I can not call my helper method directly using `$this` ?

  13. Kenneth Onah says:

    Thanks Alexey. You just saved me tons of hours of reading through the official documentation.

  14. Ajay Kumar Singh says:

    thanks…before i was very confuse regarding magento 2. but now feeling good..

    Great tutorial! thanku so much Ksenia Dobreva

  15. Center says:

    Thanks for this how-to !

    I am not actually a developer but it’s good to have some more insights of the file and folder structures for future Amasty M2 modules we surely need on our new website

    I do not see the Amasty admin settings after completing step “Create settings” with the files routes.xml and system.xml

    I also added Amasty\HelloWorld\Model\Source.Align.php from the zip file

  16. Dzmitry says:

    Thanks for an article

  17. Mihai says:


    Excellent tutorial and the source files are golden.
    I’m having a bit of a problem.

    The database table is not being created. In the log files it says that it doesn’t exist and I also verified it in phpMyAdmin.

    It worked once, the table got created then I disabled and deleted the module and the table, from the database and after that I ran into this problem.

    Could you maybe give me an idea as to what’s going on ?


    • Ksenia Dobreva Ksenia Dobreva says:

      Hey there, thanks for reading! Happy it was useful for you.
      As for your question, well, it’s hard to see from here why the database table isn’t created. We can suppose that you didn’t run setup:upgrade, or you run it and added the scripts afterwards, and they weren’t executed.

      • Mihai says:

        Thank you for getting back to me.
        You are right. I added some scripts after setup:upgrade.
        All works fine now.

        Thanks again!

  18. Jose Reyes says:

    getCollection is too broad. I have being trying to create a function to do a custom data pull but not sure what file I should put it in and then how to call it from my observer class. Could you point me in the right direction?

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey Jose, thanks for your comment.
      In the class collection you can add the new method with conditions for the selection and get the necessary custom data. In the observer you can get this collection via object manager.
      Hope that helps!

  19. Ezequiel says:

    Great article!

    Got a doubt for overriding a extension module, let say i’ve created a new one, but now i’m creating a new theme and want to override only the css of the module.

    app > design > bla bla bla done it just like Magento 2 in the official documentation but can’t get to call the css. Can you guide me through maybe?

  20. sunny says:

    its a nice tutorial, really thankfull to u.

  21. Nhu says:

    Hi all,
    I run “php bin/magento setup:di:compile” command, it take me 4h, i dont know what wrong wit me, how about you.

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey there and thanks for the question. Are you seeing any errors? Are you using the latest Magento version? Are you sure your server suits the Magento 2 requirements?

      • Nhu says:

        I am running Magento 2 with the latest version and i am running on local machine, it run nomally but waste many time when compile, how long did it take for you?
        Thanks, Ksensia Dobreva.

  22. mk says:

    You don’t mention the location of system.xml and I can’t find it, beginners can’t complete the third step :(

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey there, you can easily download the example extension at the end of the article (subscription form) and investigate the structure of the extension in every way. Also, the example path for the file is app\code\Amasty\CustomerAttributes\etc\adminhtml\system.xml
      Hope that helps.

  23. Dieter Walckiers says:

    Hello Ksenia. This helped me a lot further, thanks a lot for explaining this in a clear way.
    One question, if I wanted to integrate a custom extension like this in another place, like the sidebar, how would I go about it? Thanks a lot

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey Dieter, thanks for reading! Glad that it was useful for you.

      Go to app/code/Amasty/HelloWorld/view/frontend/layout/catalog_product_view.xml and enter the different location by replacing with your own needed variant. Hope that helps!

      • Dieter Walckiers says:

        Hello Ksenia, thanks for your reply.
        I thought so too, but I tried replacing the name of the referenceContainer element in there with “sidebar.additional” (refreshed and flushed caches), but nothing shows up in the sidebar… I’m still finding my way around magento 2.

        • Ksenia Dobreva Ksenia Dobreva says:

          Dieter, did you place an output like < ?php echo $this->getChild(‘your_block’)?> in your template?

  24. priyansh agrawal says:

    i have run “php bin/magento setup:di:compile” but it takes a long time to respond it stuck first at somewhere:- “repositories code generation…1/7 [===>———] 14% 2sec 42.0 MB” and this is my apache server error.log file . i am running on windows using xampp…plz help .

    [Mon Aug 22 17:09:58.647023 2016] [ssl:warn] [pid 5268:tid 392] AH01909: server certificate does NOT include an ID which matches the server name
    [Mon Aug 22 17:09:58.770228 2016] [core:warn] [pid 5268:tid 392] AH00098: pid file D:/xampp/apache/logs/ overwritten — Unclean shutdown of previous Apache run?
    [Mon Aug 22 17:09:58.970254 2016] [ssl:warn] [pid 5268:tid 392] AH01909: server certificate does NOT include an ID which matches the server name
    [Mon Aug 22 17:09:59.503739 2016] [mpm_winnt:notice] [pid 5268:tid 392] AH00455: Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.8 configured — resuming normal operations
    [Mon Aug 22 17:09:59.503739 2016] [mpm_winnt:notice] [pid 5268:tid 392] AH00456: Apache Lounge VC14 Server built: Dec 9 2015 10:17:39
    [Mon Aug 22 17:09:59.503739 2016] [core:notice] [pid 5268:tid 392] AH00094: Command line: ‘d:\\xampp\\apache\\bin\\httpd.exe -d D:/xampp/apache’
    [Mon Aug 22 17:09:59.507716 2016] [mpm_winnt:notice] [pid 5268:tid 392] AH00418: Parent: Created child process 4140
    [Mon Aug 22 17:10:00.390955 2016] [ssl:warn] [pid 4140:tid 288] AH01909: server certificate does NOT include an ID which matches the server name
    [Mon Aug 22 17:10:00.565223 2016] [ssl:warn] [pid 4140:tid 288] AH01909: server certificate does NOT include an ID which matches the server name
    [Mon Aug 22 17:10:00.613228 2016] [mpm_winnt:notice] [pid 4140:tid 288] AH00354: Child: Starting 150 worker threads.

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey Priyansh,

      thanks for your question. Does it stop for ever or does it still end but just works slowly?

      • priyansh agrawal says:

        just works slowly…it took around 1.5 hrs to complete

        • priyansh agrawal says:

          also i want to ask u one thing that why ur extension show “hello world” only when we clicked any product on frontend page? what should we do to make it visible on homepage of luma(frontend)
          which files we have to edit and what we have to write in them to see this change?/

          • priyansh agrawal says:

            can u give link/links of such sources which have tutorials for building these kind of basic plugins or have plugins to free download ..i need this only for practicing purpose

          • Ksenia Dobreva Ksenia Dobreva says:

            It’s because we’re using this layout:


            If you replace catalog_product_view with a certain page, then the block will be displayed there.

  25. sushil says:

    Hello Ksenia

    I am using your sample extension magento2 i.e

    I get the code and its successfully working…

    But I need some modification in that…I want to show this on cart page in frontend rather than product detail page….Is that possible?

    What changes i need to do that for showing on cart page in frontend?

    Please reply me ASAP.


  26. Manoj says:

    Guys can you guide me on magento2 extension contribution steps.

  27. Kaushal says:

    Hi Ksenia,

    Thanks from the bottom of the heart :)
    That you explained in detail this extension – It’s development steps & the usage of each step…..what one developer actually wants :)

    God Bless You :)

  28. Marcio Shimoda says:

    Hello! Nice article. Could you tell me where the values of the amasty_helloworld table are registered and how the values in this module are stored?

    • Ksenia Dobreva Ksenia Dobreva says:

      Thanks for reading!

      Unfortunately, Alexey didn’t create a controller for adding the values into the table, that’s why there’s no answer for your question in this article. But we will cover it in the upcoming blog posts!

  29. Randy says:

    Someone already mentioned it, but you guys didn’t look like you fixed it.

    There is no <?php declaration at the top of registration.php.
    If you have an article on creating an extension, you're most likely dealing with individuals who don't have much experience in building Magento2 extensions, and may just be copy-pasting.

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey Randy, indeed, thanks for pointing out!

      However, we highly encourage our readers not to copy-paste anything from the web and to try to understand the code before using it, which is more helpful for Magento education.


  30. Kevin says:

    hello, can you explain what is Amasty_HelloWorld::amasty_helloworld means in system.xml? I stucked while creating system.xml

    • Ksenia Dobreva Ksenia Dobreva says:

      Hey Kevin, thanks for the question. Amasty_HelloWorld::amasty_helloworld is the resource name, which is used to grant permissions with the help of acl.
      This code will be used in acl.xml to restrict the visibility of this setting for some admin users.
      Hope that helps!

      • Kevin says:

        thanks, I understand now.
        Anyway, how to use model with some conditions based on user input? can you get where id = some number or title = some title? how to do that?

        • Ksenia Dobreva Ksenia Dobreva says:

          could you please explain what you mean here?
          I’m not sure I’m getting your question right. Thanks!

  31. Jin says:

    Hi Ksenia,

    Good tutorial! Took me awhile to figure out the logic, but I finally understand.
    I have some questions though, hope you can help me clearify.

    What happens when I disable the module in the admin backend?
    I can see that the function _toHtml() in HelloWorld.php calls the getEnable() from the helper, but it is _toHtml is never called.
    And what does it do? Does it disabled the whole module except for the backend settings?

  32. Alexxx says:

    thanks for the tutorial, very helpful for a beginner. Could I suggest to add also the exact version of Magento that was used on the dev time?
    And I followed the tutorial & downloaded fiels and for me I don’t get to see the texts on the product view. The only difference in source code is that I used overall the “urn:” location instead of the “../../../”, but I think the problem should not be this small detail.
    In addition I refreshed the caches and performed a setup:di:compile. What do you think the problem is?
    Thanks 😉

    • Alexxx says:

      One more thing, if I look on the product page at the html source I can see the css file, but nothing related about the block.

      • Alexxx says:

        Ok, prety strange behavior. When I renamed the module from amasty to mytest and peformed ‘setup:upgrade’ and alle the cache refreshed I could see the changes on the product page. Has anyone any idea why? (before with the amasty name I also delete the caches, setup:upgrade and also setup:di:compile done, did I missed something?)

        • Ksenia Dobreva Ksenia Dobreva says:

          Thanks for the question!
          We’re pretty sure you missed something else, because in this extension nothing really depends on its name.

Leave a Reply

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