2

I have to override Magento_Sales::order/items.phtml frontend template in custom module. I have added below code to sales_order_view.xml file of my module.

<?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">
<body>
    <referenceBlock name="order_items">
        <arguments>
            <argument name="template" xsi:type="string">Vendor_Module::order/items.phtml</argument>
        </arguments>
    </referenceBlock>
</body>
</page>

It throws below exception

Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'arguments': This element is not expected.

How I can override mentioned phtml file ? I have followed this answer but it throws same exception.

Edit: As action node is deprecated, I do not want to use it.

3 Answers 3

1

You need to use the below code for your sales_order_view.xml

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

Alternative solution:

<?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">
    <body>
        <referenceBlock name="order_items" template="Vendor_Module::order/items.phtml"/>
    </body>
</page>
7
  • But action is deprecated right?
    – amitshree
    Commented Aug 8, 2018 at 7:20
  • No you can use it in magento 2 as well but not like magento 1. Commented Aug 8, 2018 at 7:23
  • Here it says action node is deprecated devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/…
    – amitshree
    Commented Aug 8, 2018 at 7:26
  • Yes but you can still use. Which version of magento you are using? Can you try it by adding it to your code? Commented Aug 8, 2018 at 7:33
  • I am using 2.2.5 and will keep upgrading it so in future it might cause issue.
    – amitshree
    Commented Aug 8, 2018 at 7:34
0

Try below solution:

 <referenceBlock name="order_items">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Module::order/items.phtml</argument>
            </action>

    </referenceBlock>
2
  • I have seen action node is deprecated. Is there any alternative?
    – amitshree
    Commented Aug 8, 2018 at 7:23
  • yes, you are right . it is deprecated now
    – Amit Bera
    Commented Aug 8, 2018 at 7:31
0

If you want to override front end template than you have to specify action method. without action Magento can't interpret what you want to override.

So try below code:

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

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.