I want to get customer data from $customer = $block->getCustomer()
; after users sign up, Magento will send a custom confirmation email. However, the $customer return is null. Please let me know what is wrong. Thank you!
magento/app/code/ABC/Customer/view/frontend/layout/account_new_confirmation.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 Confirmation" design_abstraction="custom">
<body>
<block class="Magento\Framework\View\Element\Template" name="account.new.confirmation" template="Customer::email/account_new_confirmation.phtml"/>
</body>
</page>
magento/app/code/ABC/Customer/view/frontend/templates/email/account_new_confirmation.phtml
<?php
/** @var Magento\Framework\View\Element\Template $block */
$customer = $block->getCustomer();
?>
I just write an example of using
getCustomer
function and then you can compare the differences, How magento use this block?In
magento/module-customer/view/frontend/layout/customer_account_edit.xml
There is below code :
and then in
magento/module-customer/view/frontend/templates/form/edit.phtml
, we have something like below code, Line 21 :So If you inspect
vendor/magento/module-customer/Block/Form/Edit.php
you will notice that this block parent hasgetCustomer
function but your block and its parents do not.