So far I have created file MyModule/ProductAlert/view/frontend/email/stock.html -

<!--@subject {{trans "Products back in stock alert"}} @-->
<!--@vars {
"var alertGrid|raw":"Alert Data Grid",
"var email":"Customer Email",
"template config_path=\"design\/email\/footer_template\"":"Email Footer Template",
"template config_path=\"design\/email\/header_template\"":"Email Header Template"
} @-->
{{template config_path="design/email/header_template"}}

{{var alertGrid|raw}}

{{template config_path="design/email/footer_template"}}

And I would like to pass my variable email to .phtml file in MyModule/ProductAlert/view/frontend/templates/email/stock.phtml and call it there -

use MyModule\ProductAlert\Block\Email\Stock;

/** @var $block Stock */

    <?php if ($_products = $block->getProducts()): ?>
        <?php foreach ($_products as $_product): ?>
            <p><?= __('Hello!') ?></p>
            <p>Your email: <?php $block->getData('email') ?></p> // Email should be here
        <?php endforeach; ?>
    <?php endif; ?>

Currently it returns me nothing. How can I achieve that? Thank you!

  • have you tried {{var email}} instead of $block-getData(email)? . Some code is missing – Rafael Shkembi May 19 '19 at 19:51
  • @RafaelShkembi if I call this in .html file, then it works yes, but I want to pass that email variable from .html file and use it in .phtml file. If I call {{var email}} in .phtml file then it returns "{{var email}}" – Mee May 19 '19 at 20:01
  • I'm not sure if you can achieve that but you can try using sessions. magento.stackexchange.com/questions/94265/… – Rafael Shkembi May 19 '19 at 20:06
  • In stock.phtml file display dynamic email data? – Chirag Patel May 20 '19 at 4:38

You can create a method in MyModule\ProductAlert\Block\Email\Stock
You need to inject \Magento\Customer\Model\Session $customerSession, class to get customer Email.

protected $customerSession;

public function __construct(
    \Magento\Customer\Model\Session $customerSession,
) {
    $this->customerSession = $customerSession;

public function getCustomerEmail()
    return $this->customerSession->getCustomer()->getEmail(); 

And in your .phtml, you call it $block->getCustomerEmail()


You have to create a layout handle for it.


<tr class="email-information">
        {{layout handle="product_alert_email_stock" items=$items  area="frontend"}}

In the above code, I have declared variable items=$items

create block file for a layout handle.


namespace MyModule\ProductAlert\Block\Email\Stock;

class Items extends \Magento\Framework\View\Element\Template


Now in phtml file write below code.


<?php if ($this->getItems()) :
    foreach ($this->getItems() as $_item) :
endif; ?>

You can get data using $this->getItems() because we have create variable items=$items

I hope it helps!

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.