On customer dashboard you see this
<?= $block->getChildHtml('customer.account.dashboard.info.extra'); ?>
Can you embed content into the template using this marker in an module?
Just add content to the marker. Not override the entire info.phtml.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityOn customer dashboard you see this
<?= $block->getChildHtml('customer.account.dashboard.info.extra'); ?>
Can you embed content into the template using this marker in an module?
Just add content to the marker. Not override the entire info.phtml.
I came to a solution
app/code/Xigen/UsernameLogin/view/frontend/layout/customer_account_index.xml
<?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.username.login" template="Xigen_UsernameLogin::account/dashboard/info.phtml"/>
</container>
</block>
</referenceContainer>
</body>
</page>
Then only need to provide
app/code/Xigen/UsernameLogin/view/frontend/templates/account/dashboard/info.phtml
<?php
/** @var \Magento\Customer\Block\Account\Dashboard\Info $block */
?>
<p>
<?= $block->escapeHtml(__('Username: %1', $block->getUsername())) ?><br>
</p>
That's the cleanest solution I could get working.
Thanks Dominic for sharing, This also will work without the need to redefine the core block again
<?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">
<body>
<referenceBlock name="customer_account_dashboard_info">
<container name="customer.account.dashboard.info.extra">
<block class="Magento\Customer\Block\Account\Dashboard\Info" name="customer.account.dashboard.info.extra.username.login"
template="Xigen_UsernameLogin::account/dashboard/info.phtml"/>
</container>
</referenceBlock>
</body>
</page>