Magento – call phtml file in custom email template in magento2

emailmagento2magento2.3phtml

I need to pass the phtml file into email template. but I'm getting error like

Error Log :

Error filtering template: Invalid template file:
'Vendor_Module::emailproducts.phtml' in module: '' block's name:
'magento\framework\view\element\template_0'

I used below code in email template.

{{block class="Magento\Framework\View\Element\Template" name="email_template" area='frontend' template="Vendor_Module::emailproducts.phtml"}}

Phtml template file path

app/code/Vendor/Module/view/frontend/templates/emailproducts.phtml

Thanks in advance.

Best Answer

You need to pass something like below in your email.html file.

<td>
   {{layout handle="product_stock_alert_items"}}
</td>

Create layout file as product_stock_alert_items.xml in layout folder. Add content in it like below.

<?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" design_abstraction="custom">
        <body>
             <block class="Magento\ProductAlert\Block\Email\Stock" name="productalert.stock.alert" template="Magento_ProductAlert::stock.phtml" cacheable="false" />
        </body>
    </page>

And now create .phtml as stock.phtml in template folder and add your phtml content in it.

Related Topic