Magento2 Layout – Blank Page Issue

layoutmagento-2.1magento2

As i am trying to get my head around Magento 2 i'm trying to start to create a module. (to learn from it)

This module needs a frontend blank page that i can fill up myself.
I got it to output my main.phtml and the page also is routed good.
It works even perfectly if i would use the layout of the current theme.

But i'm trying not to get the theme layout and in order to not do that i use this in my index.php :

class Index extends Action
{
    protected $resultPageFactory;
    protected $resultPageLayout;

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

    public function execute()
    {
        $resultPageLayout = $this->resultPageFactory->create();
        $resultPageLayout->getLayout()->getUpdate()->removeHandle('default');
        return $resultPageLayout;
    }

I do get a blank page now. I'm guessing that the removeHandle('default'); just strips away all Handles and therefor leaving me with a blank page.

The problem :

It does not output my main.phtml anymore (which is a simple hello world.). I does get to my frontend/layout XML because the title of the webpage (which is defined in layout XML) is still the same.

I'm trying to figure it out. Hoping you guys can help me!

Best Answer

You need to specify page layout for the page in xml and remove code

$resultPageLayout->getLayout()->getUpdate()->removeHandle('default')

from your controller.

and add this layout="empty" on the <page> node in your xml file . You can also use 1column, 2columns-right, 3columns or empty.

For more information go to

http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-types.html

Related Topic