0

I have created custom pages a lot of times, but never face such issue. I have tried 'echo' in controller action, it is working. But all this time the layout file is not loading for that page.

Here are my code files.

Controller/Customer/Test.php

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

       $page =  $this->_pageFactory->create();
       return $page;
   }
}

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="orderbysku" frontName="orderbysku">
            <module name="Vendor_Module" />
        </route>
    </router>
</config>

view/frontend/layout/orderbysku_customer_test.xml

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="helloworld_index_index" template="Vendor_Module::index.phtml" />
        </referenceContainer>
    </body>
</page>

Any kind of help is appreciated, i'm really having a hard time to figure it out.

  • Its working fine for me can you share screen shot what you are getting ? – Ansar Husain Aug 28 '18 at 12:00
  • maybe simple spell mistake causing the problem kindly look into layout filename and folder name. – Qaisar Satti Aug 28 '18 at 12:05
  • @AnsarHusain It is showing a white/blank page. – Wasim Bajwa Aug 28 '18 at 12:09
  • I have tried the same thing in another module, and it is working. Can't figure out the problem. – Wasim Bajwa Aug 28 '18 at 12:11
  • @QaisarSatti I have checked it about 10 times – Wasim Bajwa Aug 28 '18 at 12:11
0

1. Create registration.php in app/code/Vendor/Module

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__
);

2. Create module.xml in app/code/Vendor/Module/etc

<?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="Vendor_Module" setup_version="2.0.1" />    
</config>

3. Create routes.xml in app/code/Vendor/Module/etc/frontend

<?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="orderbysku" frontName="orderbysku">
            <module name="Vendor_Module" />
        </route>
    </router>
</config>

4.Create Test.php in app/code/Vendor/Module/Controller/Customer

<?php

namespace Vendor\Module\Controller\Customer;

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

       $page =  $this->_pageFactory->create();
       return $page;
   }
}

5. Create orderbysku_customer_test.xml in app/code/Vendor/Module/view/frontend/layout

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="helloworld_index_index" template="Vendor_Module::index.phtml" />
        </referenceContainer>
    </body>
</page>

6. Create index.phtml in app/code/Vendor/Module/view/frontend/templates

This is test template
  • did it work now as i have created for you @wasim – Ansar Husain Aug 29 '18 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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