Today we will learn how to add a custom attribute in my account page in Magento 2. Previously we discussed
Step-1 Create layout file.
file: app/code/Webiators/CustomerAttribute/view/frontend/layout/customer_account_index.xml
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block class="Magento\Customer\Block\Account\Dashboard\Info" name="customer_account_dashboard_info" as="info" template="Magento_Customer::account/dashboard/info.phtml" cacheable="false"> <container name="customer.account.dashboard.info.extra"> <block class="Magento\Customer\Block\Account\Dashboard\Info" name="customer.account.dashboard.info.extra.magento.username" template="Webiators_CustomerAttribute::account/dashboard/info.phtml"/> </container> </block> </referenceContainer> </body> </page> |
Step-2 Create template file.
file: app/code/Webiators/CustomerAttribute/view/frontend/templates/account/dashboard/info.phtml.
1 2 3 |
<p> <?= $block->escapeHtml($block->getCustomer()->getCustomAttribute('magento_username')->getValue()) ?><br> </p> |
If you have any questions about this topic please mention them in the comment section below.
Hit 5 Stars if you find this post helpful
0 (based on 0 Reviews)