I found above
Created a customer.phtml in magento root folder. And also in
/vendor/magento/module-theme/view/frontend/templates/html/ directory
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); if ($customerSession->isLoggedIn()) { $customerSession->getCustomerId(); // get Customer Id $customerSession->getCustomerGroupId(); $customerSession->getCustomer(); $customerSession->getCustomerData(); echo $customerSession->getCustomer()->getName(); // get Full Name echo $customerSession->getCustomer()->getEmail(); // get Email } ?>
I don't know how to call customer.phtml.
In mangento admin. Content - pages - homepage -content, I tried these to
{{block type="core/template" template="customer.phtml"}} {{block class="Magento\Framework\View\Element\Template" template="customer.phtml"}} {{block class="Magento\Framework\View\Element\Template" template="magento_module-theme::customer.phtml"}}
Solved! Go to Solution.
Please follow the following steps:
- Create a new pltml file "customername.phtml" under this folder "vendor/magento/module-customer/view/frontend/templates"
It should be like : vendor/magento/module-customer/view/frontend/templates/customername.phtml
app/design/frontend/{{vendor_namespace}}/{{theme_name}}/Magento_Customer/templates/customername.phtml
For best approach you should create this file in your current theme.
- Then Admin->Content->Pages->"GO TO YOUR CURRENT HOMEPAGE"->Edit Page
Design->Layout Update XML
add following code:
<referenceContainer name="main"> <block class="Magento\Framework\View\Element\Template" name="customername" template="Magento_Customer::customername.phtml" /> </referenceContainer>
Save and flush cache.
Please see attachment for the reference.
- Then check homepage.
I hope it will work for you!
Hi @nudylady
You can enable template path and can check in which block or phtml file you need to show customer name.
Then you can add following code in the particular template file.
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); if ($customerSession->isLoggedIn()) { $customerSession->getCustomerId(); // get Customer Id $customerSession->getCustomerGroupId(); $customerSession->getCustomer(); $customerSession->getCustomerData(); echo $customerSession->getCustomer()->getName(); // get Full Name echo $customerSession->getCustomer()->getEmail(); // get Email } ?>
To enable template path you can get more info from following link:
https://www.mageplaza.com/kb/how-to-enable-template-path-hints-magento-2.html
I hope it will help you.
thank you
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ /* @var $block \Magento\Cms\Block\Widget\Block */ $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); if ($customerSession->isLoggedIn()) { $customerSession->getCustomerId(); // get Customer Id $customerSession->getCustomerGroupId(); $customerSession->getCustomer(); $customerSession->getCustomerData(); echo $customerSession->getCustomer()->getName(); // get Full Name echo $customerSession->getCustomer()->getEmail(); // get Email } ?> <div class="widget block block-static-block"> <?= /* @noEscape */ $block->getText() ?> </div>
template hint shows the file is
/vendor/magento/module-cms/view/frontend/templates/widget/static_block/default.phtml
The code above is my edited default.phtml.
what should I do next? I want to show the name in Page - Home page - content area.
Please follow the following steps:
- Create a new pltml file "customername.phtml" under this folder "vendor/magento/module-customer/view/frontend/templates"
It should be like : vendor/magento/module-customer/view/frontend/templates/customername.phtml
app/design/frontend/{{vendor_namespace}}/{{theme_name}}/Magento_Customer/templates/customername.phtml
For best approach you should create this file in your current theme.
- Then Admin->Content->Pages->"GO TO YOUR CURRENT HOMEPAGE"->Edit Page
Design->Layout Update XML
add following code:
<referenceContainer name="main"> <block class="Magento\Framework\View\Element\Template" name="customername" template="Magento_Customer::customername.phtml" /> </referenceContainer>
Save and flush cache.
Please see attachment for the reference.
- Then check homepage.
I hope it will work for you!
thank you I try now
Finally it worked. Thank you very much.
Hi, hope you can help me.
I want to apply this in a site Im working in, could you guide me?
Thanks!
Hi,
The file name and directory have already changed to 'vendor/magento/module-customer/view/frontend/templates/account/customer.phtml'.
Would you tell me how to do it now?
Tried but it not display name but the code that was in the phtml file that I made .