2

Magento2 after executing the file controller redirecting to a blank page. can anyone please help me?

$this->_view->loadLayout();
       $this->_view->renderLayout();

routes.xml

<router id="standard">
    <route id="promotion" frontName="promotion">
      <module name="Company_Promotion"/>
    </route>
  </router>

layout

<referenceContainer name="content">           
            <block class="Company\Promotion\Block\Promotion" name="coupon_generate" template="Company_Promotion::products.phtml"></block>
        </referenceContainer>

Thanks.

10

1 Answer 1

1

etc/frontend/routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
        <route id="promotion" frontName="promotion">
            <module name="Company_Promotion" />
        </route>
    </router>
</config>

Controller/Index/Index.php

<?php

namespace Company\Promotion\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {

        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
    }
}

view/frontend/layout/promotion_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">

    <head>
        <title>Titlename</title>
    </head> 

    <body>


        <referenceContainer name="sidebar.main">
            <block class="Company\Promotion\Block\Index\Sidebar" name="promotion_index_sidebar" before="-" template="Company_Promotion::promotion_index_sidebar.phtml"/>
        </referenceContainer>

        <referenceContainer name="content">
            <block class="Company\Promotion\Block\Index\Index" name="promotion_index_index" template="Company_Promotion::promotion_index_index.phtml"/>
        </referenceContainer>


    </body>
</page>

Block/Index/Index.php

<?php

namespace Company\Promotion\Block\Index;


class Index extends \Magento\Framework\View\Element\Template {

    public function __construct(\Magento\Catalog\Block\Product\Context $context, array $data = []) {

        parent::__construct($context, $data);

    }


    protected function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

}

view/frontend/templates/promotion_index_index.phtml

You content goes here

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.