Is their any way we can override email/shipment/track.phtml ? in module ?

created layout file

view/frontend/layout/sales_email_order_shipment_track.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="tracking">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Mod_Sales::email/shipment/track.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

created template file

view/frontend/templates/email/shipment/track.phtml

Any thoughts what can be the issue ?

有帮助吗?

解决方案

I have checked your code , you have taken wrong referenceBlock.

Please use below code in your xml file (sales_email_order_shipment_track.xml)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="sales.order.email.shipment.track">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">PackageName_Module::email/shipment/track.phtml</argument>
        </action>
    </referenceBlock>
</page>

Please create file track.phtml under path PackageName/Module/view/frontend/templates/email/shipment/

Put below code :-

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php /* @var \Magento\Framework\View\Element\Template $block */ ?>
<?php $_shipment = $block->getShipment() ?>
<?php
/* @var \Magento\Sales\Model\Order $_order */
$_order = $block->getOrder() ?>
<?php if ($_shipment && $_order) : ?>
    <?php $trackCollection = $_order->getTracksCollection($_shipment->getId()) ?>
    <?php if ($trackCollection) : ?>
        <br />
        <table class="shipment-track">
            <thead>
            <tr>
                <th><?= $block->escapeHtml(__('Shipped By dhwani')) ?></th>
                <th><?= $block->escapeHtml(__('Tracking Number')) ?></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($trackCollection as $_item) : ?>
                <tr>
                    <td><?= $block->escapeHtml($_item->getTitle()) ?>:</td>
                    <td>
                        <a href="<?= $block->escapeUrl($block->getTrackingUrl()->getUrl($_item)) ?>" target="_blank">
                            <?= $block->escapeHtml($_item->getNumber()) ?>
                        </a>
                    </td>
                </tr>
            <?php endforeach ?>
            </tbody>
        </table>
    <?php endif; ?>
<?php endif; ?>

In above code i have changed title like below to check it is working or not.

<th><?= $block->escapeHtml(__('Shipped By dhwani')) ?>

And i have got below output in email:-

https://prnt.sc/103grlp

许可以下: CC-BY-SA归因
scroll top