0

I'm a beginner in magento and I have a custom email template as follows

wishlist_email_template.html

{{template config_path="design/email/header_template"}}
<table cellspacing="0" cellpadding="0" border="0" width="100%">
    <tr>
        <td align="center" valign="top" style="padding:20px 0 20px 0">
            <table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
                <tr>
                    <td valign="top">
                        <h1 style="font-size:22px;font-weight:normal;line-height:22px;margin:0 0 11px 0;">{{var heading}}</h1>
                    </td>
                </tr>
                <tr>
                    <td>
                        {{var feedback}}
                    </td>
                </tr>
                {{layout handle="wishlist_email_products" products=$products area="frontend"}}

                <tr>
                    <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA;text-align:center;">
                        <center>
                            <p style="font-size:12px;margin:0;">
                                <strong> Thank you</strong>
                            </p>
                        </center>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
{{template config_path="design/email/footer_template"}}

SendWishlistEmail.php

   foreach ($toEmail as $receiver) {
            $receiverMail = $receiver;
            try {
                // template variables pass here
                $templateVars = [
                    'heading' => 'Wishlist',
                    'msg' => 'test',
                    'msg1' => 'test1',
                    'products'=> $products,
                    'images'=> $images,
                    'feedback' =>$feedback
                ];

                $storeId = $this->storeManager->getStore()->getId();

                $from = ['email' => $fromEmail, 'name' => $fromName];
                $this->inlineTranslation->suspend();

                $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
                $templateOptions = [
                    'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
                    'store' => $storeId
                ];
                $transport = $this->transportBuilder->setTemplateIdentifier($templateId)
                    ->setTemplateOptions($templateOptions)
                    ->setTemplateVars($templateVars)
                    ->setFrom($from)
                    ->addTo($receiverMail)
                    ->getTransport();
                $transport->sendMessage();
                $this->inlineTranslation->resume();
            } catch (\Exception $e) {
                $this->_logger->info($e->getMessage());
            }
        }

$products is my array, I'm trying to get my product data from product array using {{layout handle="wishlist_email_products" products=$products area="frontend"}}.

wishlist_email_products.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="Email Product List" design_abstraction="custom">
    <body>
        <block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="email/product.phtml"/>
    </body>
</page>

product.html

<?php
/**
 * @var $block Magento\Framework\View\Element\Template
 */
$products = $block->getProducts();
?>
<?php foreach ($products as $product): ?>
    <tr>
        <td><?php echo $product->getSku() ?></td>
        <td><?= $product->getName() ?></td>
    </tr>
<?php endforeach; ?>

I get the error Error

filtering template: Invalid template file: 'app/code/NeoSolax/Custom/view/frontend/templates/email/product.phtml' in module: '' block's name: 'additional.product.info'

in my sent email Please help.

0

Change the xml will fix:

<?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="Email Product List" design_abstraction="custom">
<body>
    <block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="NeoSolax_Custom::email/product.phtml"/>
</body>

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.