2

I am trying to override vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml in my module.

I have tried below mentioned mentioned method but its not working.

I have copied vendor/magento/module-sales/view/frontend/layout/sales_email_order_renderers.xml in my module app/code/Company/Module/view/frontend/layout/sales_email_order_renderers.xml and updated code with below mentioned code :

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="sales.email.order.renderers">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Company_Module::email/items/order/default.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

and copied default.phtml file in my module folder app/code/Company/Module/view/frontend/templates/email/items/order/default.phtml and added few texts but those texts are not appearing. Please help.

2 Answers 2

6

The block you are trying to modify the template of is within the "sales.email.order.renderers" block so your referencing the wrong block. The block you want to modify has no name however and just the alias "default". Have you tried something like:

<?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" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="sales.email.order.renderers">
            <block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" as="default" template="Vendor_Module::email/items/order/default.phtml"/>
        </referenceBlock>
    </body>
</page>

Also i was told yesterday that the action tag is being depreciated and now is best to use below to override templates:

<referenceBlock name="sales.email.order.renderers" template="Company_Module::email/items/order/default.phtml" />

However I think the name is wrong as the template we need to modify is within this block:

<block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" as="default" template="email/items/order/default.phtml"/>

Rather than the block "sales.email.order.renderers" and am unsure if below would work with the alias:

<referenceBlock name="default" template="Company_Module::email/items/order/default.phtml" />

Reading here Magento 2: How to change template of a block without "name" it just seems to show what i suggested.

2
  • No problem glad it worked.
    – harri
    Jun 3, 2017 at 12:47
  • <?xml version="1.0"?> <page xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom"> <body> <referenceBlock name="sales.email.order.renderers"> <block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" as="default" template="Vendor_Module::email/items/order/default.phtml"/> </referenceBlock> </body> </page> IT IS WORK FOR ME THANKS Sep 25, 2018 at 5:30
0

This is actually really straight forward since the block has a name. I am going to assume you already have a custom module created for accomplishing this. Within you custom module, copy the phtml file and make necessary changes. Keep the same folder structure. Copy the xml file and replace the referenceBlock information with below.

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

That's it! Now if the block doesn't have a name only alias it is much more difficult.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.