0

First
I have created a module and place it in a file I want to override

\app\code\Vendor\Module\view\adminhtml\templates\widget\grid\extended.phtml

The original location is

vendor\magento\module-backend\view\adminhtml\templates\widget\grid\extended.phtml


Second
I added backend_widget_grid.xml located in

\app\code\BodyMod\OrdersPopupButton\view\adminhtml\layout\backend_widget_grid.xml

And the content of the xml file is:

<?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>
        <referenceBlock name="widget.extended">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Module::widget/grid/extended.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

I don't see my edits so can somebody tell me where is my mistake?

1
  • Is backend_widget_grid.xml a custom layout?
    – Haritha
    Commented Mar 22, 2018 at 9:55

1 Answer 1

1

Override Magento\Backend\Block\Widget\Grid\Extended like this:

<?php

namespace Vendor\Module\Block\Adminhtml\Widget\Grid;

class Extended extends \Magento\Backend\Block\Widget\Grid\Extended
{
    protected $_template = 'Vendor_Module::widget/grid/extended.phtml';
}

and in di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Backend\Block\Widget\Grid\Extended" type="Vendor\Module\Block\Adminhtml\Widget\Grid\Extended" />
</config>
9
  • This looks like a way to override php not phtml. Is the first file you meantion named Extended.php in Vendor\Module\Block\Adminhtml\Widget\Grid\ and should di.xml be in etc/adminhtml/ ? Commented Mar 22, 2018 at 11:00
  • 1
    yes, this is the way. You cannot override the template of this block inside a layout file because this block is not called directly in any layout .
    – George M
    Commented Mar 22, 2018 at 12:24
  • Yes, i found the same way elsewhere so you are right, but I still can't see my edits Commented Mar 22, 2018 at 12:45
  • Unless it's unavoidable please do not declare or override templates this way. It makes it very difficult for front-end developers to work with it, although at times the core hard codes templates this way (like this) :(
    – Ben Crook
    Commented Mar 22, 2018 at 13:16
  • yes, i agree with you, @BenCrook. Probably, the best way to do this override is to override the template directly inside your custom admin theme folder, under Magento_Backend
    – George M
    Commented Mar 22, 2018 at 14:11

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.