1

It's my execute method from controller:

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

It's my layout inside the <page>:

<body>
    <referenceContainer name="content">
        <block
            class="Magento\Framework\View\Element\Template"
            name="printshipment_index_index"
            template="Module_PrintShipment::print_shipment.phtml"/>
    </referenceContainer>
</body>

In this case I have default Magento layout with header, footer etc. And I need fully empty page. I have tried to add

<update handle="empty"/>

but then my block doesn't appear. What can you advise me?

0

If you want empty layout then you can pass this on <page> tag, for example

<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 class="Magento\Framework\View\Element\Template" name="printshipment_index_index" template="Module_PrintShipment::print_shipment.phtml" />
        </referenceContainer>
    </body>
</page>
0

Follow default vendor/magento/module-theme/view/frontend/layout/print.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="header.container" remove="true"/>
        <referenceBlock name="catalog.topnav" remove="true"/>
        <referenceContainer name="footer-container" remove="true"/>
        <referenceContainer name="before.body.end">
            <block class="Magento\Framework\View\Element\Template"  name="printshipment_index_index"          template="Module_PrintShipment::print_shipment.phtml"/>
        </referenceContainer>
    </body>
</page> 

or you can use simply

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="print" />
    <body>
          <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template"  name="printshipment_index_index"          template="Module_PrintShipment::print_shipment.phtml"/>
          </referenceContainer>
    </body>
</page>
  • Can we use layout="empty" ? – Keyur Shah Dec 27 '17 at 18:54
  • @KeyurShah yes we can use layout="empty" too. – Qaisar Satti Dec 27 '17 at 19:01
  • Unfortunately, with your method, as well as with layout="empty", my .phpml file is not rendered(( It is OK when layout isn't empty. – Skorzhyk Dec 28 '17 at 9:42
  • @Skorzhyk i checked this code it is working with custom luma and blank theme. – Qaisar Satti Dec 28 '17 at 10:00
0

To prevent the "default" layout handles being applied you may need to use this in your controller execute function:

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

return $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);

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.