0

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.

4

2 Answers 2

1

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.

1
  • Magento 1 How to add website filter in app\locale\en_US\template\email\sales\order_new.phtml, my workout => paste.ofcode.org/G7k6QZMMEMHE8yHCH3kj6z any help thanks @Kazim Noorani
    – Gem
    Mar 17, 2020 at 10:38
0

There is an issue in your Email template file. Your given template file is not found in an assigned block(Magento\Framework\View\Element\Template). so you need to create a custom block and have to assign that block to the phtml file.

And extend your custom block to Magento\Framework\View\Element\Template

Check below detail description example.

app/code/Namespace/Modulename/view/frontend/email/test_reminder.html

<tr class="email-information">
    <td>
        {{layout handle="test_email_log_order_items" items=$items area="frontend"}}
    </td>
</tr>

app/code/Namespace/Modulename/view/frontend/layout/test_email_log_order_items.xml

<block class="Namespace\Modulename\Block\EmailLog\Items" name="items" template="email/items.phtml" cacheable="false"></block>

Namespace\Modulename\Block\EmailLog\Items

<?php
namespace Namespace\Modulename\Block\EmailLog;

class Items extends \Magento\Framework\View\Element\Template
{

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context, 
        array $data = array()
    ) {
        parent::__construct($context, $data);        
    }        

}

app/code/Namespace/Modulename/view/frontend/templates/email/items.phtml

<?php
echo "This data is dynamic data and can be changed according to need.";
// You can print data according to your need. 
// You can also get the parameters on this file.
?>

app/code/Namespace/Modulename/etc/email_templates.xml

<template id="test_email_template" label="Test email template" file="test_reminder.html" type="html" module="Namespace_Modulename" area="frontend"/>

If you are giving a select email template in system configuration then your config.xml should be like below.

app/code/Namespace/Modulename/etc/config.xml

<default>
    <tabname>            
        <groupname>                
            <fieldname>test_email_template</fieldname>
        </groupname>            
    </tabname>
</default>

That's it. It's work for me! I hope it helps.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .