Magento2 – Custom Module Layout Issue

magento-2.1magento2magento2.2module

Created Magento 2 custom module but the layout seems not showing anything.
It is supposed to show some output but it is showing white blank screen in the page.

Please help

My URL
http://localhost/PG2/helloworld/Index/Index

Folder Structure:
http://prntscr.com/g1t4sp

controller code

      <?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()
            {

                // echo "Hello ";

                $resultPage = $this->_resultPageFactory->create();
                return $resultPage;
            }
        }

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>

module.xml code

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

helloworld_Index_Index

        <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="helloworld.phtml" />
                </referenceContainer>
            </body>
        </page>

block class file

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

Best Answer

I checked your code. You made simple file naming mistakes

1) Rename helloworld_Index_Index.xml to helloworld_index_index.xml (make router name in lowercase)

2) Remove space before file name at app/code/Inchoo/Helloworld/view/frontend/templates rename '(space)helloworld.phtml' to 'helloworld.phtml'

Now keep this code in helloworld.phtml to test your code

I am testing buddy 

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

Now remove var/generation and flush cache and try it's working now.