1

I am in new Magento 2 and have created a custom module, its working fine with the url(http:///modulename/index/test) but need to call it on home page. I mean when home page loaded, module would be called automatically. How it possible?

Below is the steps which I followed during module creation -

Step 1: Created the Namespace and module folder

Step 2: Created etc/module.xml file

<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ignvia_HelloWorld" setup_version="1.0.0">
</module>

Step 3: Created etc/registration.php file

<?php

\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Ignvia_HelloWorld', DIR );

Step 4: Created etc/frontend/routes.xml file

<?xml version="1.0" ?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
    <route frontName="helloworld" id="helloworld">
        <module name="Igniva_HelloWorld"/>
    </route>
</router>

Step 5: Created Controller/Index/Test.php

<?php

namespace Igniva\HelloWorld\Controller\Index;

class Test extends \Magento\Framework\App\Action\Action { protected $_pageFactory;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $pageFactory)
{
    $this->_pageFactory = $pageFactory;
    return parent::__construct($context);
}

public function execute()
{
    echo "Hello World";
    exit;
}

}

Thanks.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

0

To load your custom module in homepage, your code should be called in cms_index_index layout(not in core file).you have to define in custom file.

sabarivel
  • 11
  • 3