Magento – Magento 2: change template for block in “sales.email.order.renderers”

blocksemail-templateslayoutlayout-updatemagento2

There is layout configuration file module-sales/view/frontend/layout/sales_email_order_renderers.xml:


<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="email/items/order/default.phtml"/>
</referenceBlock>
</body>
</page>

I need to change default template for block Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder. I have created own configuration update .../view/frontend/layout/sales_email_order_renderers.xml in own module with:


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

but default template is used for the block as before.

Can I change template for block Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder using layout updates?

Best Answer

You can just copy vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml to app/design/frontend/[VENDOR]/[THEME]/Magento_Sales/templates/email/items/order/default.phtml and make your changes.

But you can also extend vendor/magento/module-sales/view/frontend/layout/sales_email_order_renderers.xml to app/design/frontend/[VENDOR]/[THEME]/Magento_Sales/layout/sales_email_order_renderers.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" 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="email/items/order/default.phtml"/>
        </referenceBlock>
    </body>
</page>

And change whatever you need.