1

I'm working on a module in the admin part but can someone tell me please how I can load just my template from my controller without the admin menu in the left, the title and the footer.

here is one of my secondary controller :

<?php
  namespace Mymodule\AdminPage\Controller\Adminhtml\Secondcontroller;

  class Index extends \Magento\Backend\App\Action
  {
    /**
    * @var \Magento\Framework\View\Result\PageFactory
    */
    protected $resultPageFactory;

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

    public function execute()
    {
        return  $resultPage = $this->resultPageFactory->create();
    }
  }
?>

and there is his the layout :

<?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">
    <head>
        <title>
            Module Mymodule
        </title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Backend\Block\Template" template="Mymodule_AdminPage::secondary.phtml"/>
        </referenceContainer>
    </body>
</page>

1 Answer 1

0

Add this code in your layout.xml file under <body> tag

<referenceBlock name="page.menu" remove="true"/>
<referenceBlock name="footer" remove="true"/>
<referenceBlock name="header" remove="true"/>
<referenceBlock name="logo" remove="true"/>
<referenceBlock name="page.title" remove="true"/>

After that you have to override below file

vendor/magento/module-backend/Model/View/Result/Page.php

inject \Magento\Framework\App\Request\Http $request in __construct method and add $this->request = $request; in __construct function

and in this file change setActiveMenu function to these

public function setActiveMenu($itemId)
{
    $action     = $this->request->getFullActionName();
    if($action != 'yourrouter_controller_action')
    {
        $menuBlock = $this->layout->getBlock('menu');
        $menuBlock->setActive($itemId);
        $parents = $menuBlock->getMenuModel()->getParentItems($itemId);
        foreach ($parents as $item) {
            /** @var $item \Magento\Backend\Model\Menu\Item */
            $this->getConfig()->getTitle()->prepend($item->getTitle());
        }
    }
    return $this;
}
0

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.