Write rule emails with native Magento templates and matched-item variables
Rule emails are ordinary Magento DB email templates from Marketing > Communications > Email Templates. There is no separate template language: the standard directives ({{var}}, {{trans}}, {{if}}, {{layout}}, {{for}}) work as they do in core sales emails, and a template you write here is a normal template you can manage, translate, and back up like any other.
Variables
Every rule with Send Email on passes these variables to its template:
| Variable | Type | Notes |
|---|---|---|
order | Order object | Reloaded fresh at send time: {{var order.increment_, {{var order.getShippingAddress().getName()}} |
customer_ | string | Registered customer name, or the guest’s billing name |
store | Store object | For example {{var store.getFrontendName()}} |
rule_ | string | Admin name of the rule that queued the email |
matched_ | array | Snapshot of the matched items: sku, name, qty, row_, product_, product_, image_, plus every attribute the product carries |
matched_ | string | A pre-rendered, email-safe table of the matched items (Product, SKU, Qty) |
Any product attribute is available as {{var item.your_attribute_code}} inside a loop, with nothing to configure first. The built-in fields always win over an attribute of the same name, so a product renamed after the order still shows what the customer bought. cost is never captured, because the snapshot is stored in the Email Log. product_url is omitted for products that are not individually visible, rather than linking to a page that returns 404.
The rule form has a collapsible Variable Reference panel with this table and both usage forms below, for reference while you write.
Snapshot timing
The variables do not all reflect the same moment:
matched_itemsandmatched_items_htmlreflect the moment the rule matched (order placement, invoice, or shipment). With a three-day delay, the email still shows what was ordered, even if the product has since been edited or deleted.orderreflects send time. It is reloaded right before rendering, so status and address changes since queueing show up.
Form 1: the ready-made table
One directive drops in the whole table. From the “OCM Product Warranty Information” sample:
<p>Thank you for order <strong>#{{var order.increment_id}}</strong> from {{var store.getFrontendName()}}. The product(s) below carry a manufacturer warranty.</p>
{{var matched_items_html|raw}}
<p style="margin-top:24px;">Questions about your warranty coverage? Just reply to this email.</p>The |raw modifier is required. Without it the table HTML is escaped and renders as literal markup.
Form 2: a custom loop
For your own columns, styling, or per-product values, loop over matched_items. From the “OCM Product Instruction Manual” sample, where manual_url is a product attribute:
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse;margin-top:12px;"> <tr> <th align="left" style="padding:8px;border-bottom:2px solid #e0e0e0;">Product</th> <th align="left" style="padding:8px;border-bottom:2px solid #e0e0e0;">SKU</th> <th align="left" style="padding:8px;border-bottom:2px solid #e0e0e0;">Manual</th> </tr> {{for item in matched_items}} <tr> <td style="padding:8px;border-bottom:1px solid #e0e0e0;">{{var item.name}}</td> <td style="padding:8px;border-bottom:1px solid #e0e0e0;">{{var item.sku}}</td> <td style="padding:8px;border-bottom:1px solid #e0e0e0;"><a href="{{var item.manual_url}}" style="color:#1979c3;">Download manual</a></td> </tr> {{/for}}</table>Sample templates
“OCM Product Warranty Information” and “OCM Product Instruction Manual” are installed on the first setup:upgrade, one per usage form. Duplicate and edit them rather than starting from blank. Re-running setup:upgrade never overwrites your changes, and renaming a sample does not cause it to be reinstalled.
Editing templates from the rule form
Next to the Email Template field:
- + Create New Template opens a small modal (Name, Subject, Content) that creates a real Magento email template and selects it. The modal is plain text only; open the template in Marketing > Communications > Email Templates for the WYSIWYG editor and variable wizard.
- Edit opens the same modal for the selected template.
- Manage all templates links to the core email template grid.
The dropdown refreshes without a page reload. The modal requires Magento’s own email-template permission in addition to rule management access.
Emails render in the order’s store view, so locale, currency, and theme-scoped template resolution match that store.