0

I need a way to send an array of objects in email, So I can iterate those and create a table in email. I have tried creating email handle but no success.

Any help is much appreciated!

Thanks

1

You can but you need to render a block to email template like order&invoice Email. Magento renders order & invoice items render at email using layout & block & template.

{{layout handle="sales_email_order_items" order=$order area="frontend"}}

In order template, you can see above code.

Means Magento email template is using layout file sales_email_order_items and passing order object using order=$order and sets area using area="frontend"

Assume your parameter name is mydata a template variable at php code is

templateVars = array(
    'customer_name' => 'John Doe',
    'mydata'   => $yourObjectarray
);

using as https://webkul.com/blog/magento2-create-custom-email-templates/ as the example to show send parameters

  • First, create a layout file at frontend>layout folder. Example: my_custom_lays.
  • And then you need to call this layout at the email HTML template using`

    {{layout handle="[MyHandler]" [variableName]=$variableName area="frontend"}}

  • After that create a block and invoke the Block using this layout

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.