1

On customer dashboard you see this

https://github.com/magento/magento2/blob/ddf42caaf25311f10b23b95a92746f99943e045e/app/code/Magento/Customer/view/frontend/templates/account/dashboard/info.phtml#L23

<?= $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.

2 Answers 2

0

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.

0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.