I am working on a simple module and trying to display a block. All that is showing up is a blank page. If I put an echo "blah"; exit() in my controller, it shows the output. No errors in my log files. Below is the code
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magento2_HelloWorld',
__DIR__
);
Magento2/HelloWorld/etc/frontend/routes.xml
<?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 id="magento2" frontName="helloworld">
<module name="Magento2_HelloWorld" />
</route>
</router>
</config>
Magento2/HelloWorld/Block/Index.php
<?php
namespace Magento2\HelloWorld\Block;
class Index extends \Magento\Framework\View\Element\Template {
public function __construct(\Magento\Catalog\Block\Product\Context $context, array $data = []) {
parent::__construct($context, $data);
}
public function sayHello()
{
return __('Hello World');
}
protected function _prepareLayout()
{
return parent::_prepareLayout();
}
}
Magento2/HelloWorld/Controller/Index/Index.php
<?php
namespace Magento2\HelloWorld\Controller\Index;
use \Magento\Framework\App\Action\Action;
class Index extends Action
{
public function execute()
{
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
}
}
Magento2/HelloWorld/view/frontend/layout/helloworld_index_index
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block class="Magento2\HelloWorld\Block\Index" name="HelloWorld_index" template="Magento2_HelloWorld::helloworld.phtml" />
</referenceContainer>
</page>
Magento2/HelloWorld/view/frontend/templates/helloworld.phtml
<?php echo $block->sayHello(); ?>
After running http://localhost/mage2/helloworld/index/index URL, I can see controller being executed but the block is not being called.
