2

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

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"}}

Thanks in advance.

13
  • Phtml template file path ? Commented Apr 29, 2019 at 9:11
  • what is the location of your phtml file ? Commented Apr 29, 2019 at 9:14
  • app/code/Vendor/Module/view/frontend/templates/emailproducts.phtml Commented Apr 29, 2019 at 9:14
  • app/code/Vendor/Module/view/frontend/templates path you add phtml file in templates folder Commented Apr 29, 2019 at 9:16
  • sanni Kalariya can you explain clearly Commented Apr 29, 2019 at 9:17

1 Answer 1

3

Steps to call PHTML file in custom email template:

  1. Write below code in email template to call custom phtml file.

    You can pass custom data in $custom_var to PHTML file.

{{layout handle="custom_email_data" custom_var=$custom_var area="frontend"}}
  1. Create layout file at below path :

Vendor/Module/view/frontend/layout/custom_email_data.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" label="Custom email data" >
    <body>
        <block class="Magento\Framework\View\Element\Template" name="custom_email_data" template="Vendor_Module::email/custom.phtml"/>
    </body>
</page>
  1. Create PHTML file at below path :

Vendor/Module/view/frontend/templates/email/custom.phtml

<?php 

/*** Get custom variable data ***/
 echo $block->getCustomVar(); 

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.