0

I am trying to create a simple hello world module, I am able to successfully create and install the module but for some reason, my screen is showing up blank. But if I echo something in controller it shows up. Can anyone help me where exactly I am going wrong? Below is my code.

I have been following this Tutorials

-app
    -code
        -KK
            -OneStepCheckOut
                -Block
                    --Main.php
                -Controller
                    -OneStepCheckOut
                        --BillingAddress.php
                -etc
                    --module.xml
                    -frontend
                        --routes.xml
                -view
                   -frontend
                     -layout
                      --oneStepCheckOut_oneStepCheckOut_billingAddress.xml
                        -templates
                            --content.phtml
                --registration.php

Controller:-

<?php 

namespace kk\OneStepCheckout\Controller\OneStepCheckout;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;
class BillingAddress extends \Magento\Framework\App\Action\Action
{
    /**
     * @var PageFactory
     */
    protected $pageFactory;
    public function __construct(Context $context, PageFactory $pageFactory)
    {
        $this->pageFactory = $pageFactory;
        return parent::__construct($context);
    }

    public function execute()
    {        
       // echo "In controller";
        $page_object = $this->pageFactory->create();
        return $page_object;
    }     
}

?>

oneStepCheckOut_oneStepCheckOut_billingAddress.xml:-

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="empty"
         xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">        
    <body>
        <referenceContainer name="content">
        <block 
            template="kk_OneStepCheckOut::content.phtml" 
            class="kk\OneStepCheckOut\Block\Main" 
            name="oneStepCheckOut" />
         </referenceContainer>
    </body>
</page>    

Main.php:-

<?php
namespace kk\OneStepCheckOut\Block;

class Main extends \Magento\Framework\View\Element\Template
{    
   public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }
}
?>

Content.phtml:-

<h1><?php echo "hello world"; ?></h1>

routes.xml:-

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

module.xml:-

<?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="kk_OneStepCheckOut" setup_version="0.0.1" />
</config>
4
  • Change file name change oneStepCheckOut_oneStepCheckOut_billingAddress.xml` to onestepcheckout_onestepcheckout_billingaddress.xml
    – Amit Bera
    Commented Mar 31, 2017 at 13:21
  • Can use please tell me the <html> body class of this class
    – Amit Bera
    Commented Mar 31, 2017 at 13:21
  • @AmitBera class is onestepcheckout-onestepcheckout-billingaddress page-layout-admin-1column
    – 3bu1
    Commented Apr 3, 2017 at 6:37
  • Thanks, by changing xml page name i got it.And can u pls post it as answer with an explanation why it has to be small letters. it would help other beginners like me. Thank u very much
    – 3bu1
    Commented Apr 3, 2017 at 6:44

1 Answer 1

0

Change layout XML file name. Magento layout xml file name always in small letters.

replace it

oneStepCheckOut_oneStepCheckOut_billingAddress.xml 

with file name

onestepcheckout_onestepcheckout_billingaddress.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.