Block is not shown on custom page

by Вероника Дерех   Last Updated July 15, 2018 17:09 PM

I am a new in Magento. I have installed Magento 2.2. and created 1 module with custom page. There is 1 block on this page, which has to be shown on it. But it is not shown. Please, help me to resolve this problem. I will write code and structure of module below.

Structure

enter image description here

Block/Helloworld.php

<?php
namespace Inchoo\Helloworld\Block;

class Helloworld extends \Magento\Framework\View\Element\Template
{
public function getHelloWorldTxt()
{
    return 'Hello world!';
}
}

Controller/Index/Index.php

<?php

namespace Inchoo\Helloworld\Controller\Index;

use Magento\Framework\App\Action\Context;

class Index extends \Magento\Framework\App\Action\Action
{
protected $_resultPageFactory;

public function __construct(Context $context,     \Magento\Framework\View\Result\PageFactory $resultPageFactory)
{
    $this->_resultPageFactory = $resultPageFactory;
    parent::__construct($context);
}

public function execute()
{
    $resultPage = $this->_resultPageFactory->create();
    return $resultPage;
}

}

etc/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="helloworld" frontName="helloworld">
            <module name="Inchoo_Helloworld" />
        </route>
    </router>
</config>

view/frontend/layout/helloworld_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
<body>
    <referenceContainer name="content">
        <block class="Inchoo\Helloworld\Block\Helloworld" name="helloworld" template="Inchoo_Helloworld::helloworld.phtml" />
    </referenceContainer>
</body>

view/frontend/templates/helloworld.phtml

<h1><?php echo $this->getHelloWorldTxt(); ?></h1>

When I open page http://localhost/magento/helloworld/index/index, page is shown, but block whith H1 and "Hello World!" is not shown. Thanks for a help.



Related Questions


Disable page cache for a single block

Updated March 06, 2017 21:09 PM


Insert block inside static block magento 2

Updated August 21, 2017 04:09 AM

Block not shown inside a page

Updated May 05, 2017 19:09 PM