Hi to all, I'm going crazy. I've read a lot of tutorial and marked "as solved" topics on override template on sales email.
I'm trying to customize the sales_email_order_items, so I've create a file in [ModuleDir]/view/frontend/layout/sales_email_order_items.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="items"> <block class="Magento\Sales\Block\Order\Email\Items" template="Vendor_Module::email/items.phtml"/> </referenceBlock> </body> </page>
and created my custom template in [ModuleDir]/view/frontend/templates/email/items.phtml
cleared cache and compiled, but nothing changed.
Someone can help me?
hi @dandreoli
if you want to override the template use below code.
<referenceBlock name="items"> <action method="setTemplate" > <argument name="template" xsi:type="string">Vendor_Module::email/items.phtml</argument> </action> </referenceBlock>
This solution with <action> is deprecated, anyway I've just tried and It doesn't work
<referenceBlock name="items"> <arguments> <argument name="template" xsi:type="string">Vendor_Module::email/items.phtml</argument> </arguments> </referenceBlock>
I've already tried this solution. At the end I0ve found an alternative way to solve.
I've delcare in di.xml
<preference for="Magento\Sales\Block\Order\Email\Items" type="Vendor\Module\Block\Order\Email\Items" />
and create a class
Vendor\Module\Block\Order\Email\Items
<?php namespace Vendor\Module\Block\Order\Email; class Items extends \Magento\Sales\Block\Order\Email\Items { }
and finally It uses my template file