Magento Email Templates: Configuring New Shipment Notifications
As a new Magento user, setting up automated shipment emails is an essential part of streamlining your e-commerce operations. In this post, we’ll tackle a common issue faced by beginners when configuring these notifications.
The Problem: Missing Template Content in Shipment Emails
Let’s dive into the code you’ve shared to understand the issue:
{{template config_path="design/email/header_template"}}
<p>
hi!
</p>
<p>
tracking numbers {{block class='Magento\Framework\View\Element\Template' area='frontend' template='Magento_Sales::email/shipment/track.phtml' shipment=$shipment order=$order}}.
</p>
<p>
end!
</p>
{{template config_path="design/email/footer_template"}}
You’ve created a new email template with the necessary headers and footers, and you’re attempting to display tracking numbers using a block. Unfortunately, when you send a shipment notification, the part where the block is supposed to render remains empty.
Two Common Approaches: Block or Layout Handling
You’ve tried two approaches suggested by Magento:
- Using the
blockclass with theMagento_Sales::email/shipment/track.phtmltemplate. - Using the
layouthandle “sales_email_order_shipment_items” with shipment and order variables.
The Root Cause: Incorrect Template Path or Variable Syntax
The issue lies in the way you’re referring to the templates. Magento expects a specific naming convention for email templates, which is not being followed here.
In your code:
Magento_Sales::email/shipment/track.phtmlshould be replaced withsales_email_order_shipment_track.- The variable syntax
$shipmentand$orderneeds to adhere to Magento’s standard for passing variables in email templates, which is{block shipment=$block.shipment order=$block.order}.
The Corrected Code
Let me provide the corrected version of your template:
{{template config_path="design/email/header_template"}}
<p>
hi!
</p>
<p>
tracking numbers {{block class='Magento\Framework\View\Element\Template' area='frontend' template='Magento_Sales::sales_email_order_shipment_track.phtml' shipment=$block.shipment order=$block.order}}.
</p>
<p>
end!
</p>
{{template config_path="design/email/footer_template"}}
Best Practices for Magento Email Templates
-
Use Magento’s standard template names: Always use the Magento-provided templates and their corresponding handles to ensure compatibility with the system.
-
Pass variables in the correct format: When passing variables like
$shipmentor$order, always use the format{block shipment=$block.shipment order=$block.order}within your blocks. -
Test thoroughly: Conduct multiple tests across different email clients and devices to ensure your emails render correctly everywhere.
Conclusion
Configuring new shipment emails in Magento is a powerful feature that can significantly improve customer satisfaction. By understanding the correct syntax for template paths, variable passing, and following Magento’s best practices, you’ll be able to create effective and reliable automated notifications.
Remember, the key lies in using Magento’s built-in templates and handles, which are designed to work seamlessly with the system. Always refer to our guide on customizing email templates for a more detailed walkthrough of this process.
Happy coding!