I have tried the following:
Observer
...
$transport = $observer->getTransport();
$transport->setTemplateVars([
'products' => [
['name' => 'Product1'],
['name' => 'Product2']
]
]);
...
order_new_guest.html
{{layout handle="sales_email_order_vendor_module_items" order=$order area="frontend"}}' products=$products}}
email/template.phtml
<p>HELLO!</p>
<?php //print_r(count($this->getProducts())); ?>
<?php foreach ($this->getProducts() as $_item): ?>
<p><?php echo $_item['name'] ?></p>
<?php endforeach; ?>
The issue:
In foreach I get error:
Error filtering template: Warning: Invalid argument supplied for foreach() in .../htdocs/app/code/Vendor/Module/view/frontend/templates/email/template.phtml on line 3
If I count() I get error:
Error filtering template: Warning: count(): Parameter must be an array or an object that implements Countable in .../htdocs/app/code/Vendor/Module/view/frontend/templates/email/template.phtml
UPDATED:
<?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">
<body>
<block class="Magento\Framework\View\Element\Template" name="sales_email_order_vendor_module_items" template="Vendor_Module::email/template.phtml"/>
</body>
</page>
Am i missing something can anyone see it? Thanks in advance!