1

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.

  • Phtml template file path ? – Savan Patel Apr 29 at 9:11
  • what is the location of your phtml file ? – Manashvi Birla Apr 29 at 9:14
  • app/code/Vendor/Module/view/frontend/templates/emailproducts.phtml – venkata prasad Apr 29 at 9:14
  • app/code/Vendor/Module/view/frontend/templates path you add phtml file in templates folder – sanni kalariya Apr 29 at 9:16
  • sanni Kalariya can you explain clearly – venkata prasad Apr 29 at 9:17
0

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, privacy policy and cookie policy

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