0

Magento 2 newbie. I am trying to override the default 'Customer Account Edit' form on the Frontend. I'm not able to get my template to "override", its always loading the default template [/html/public/vendor/magento/module-customer-custom-attributes/view/frontend/templates/customer/form/edit.phtml]. The issue may be with my layout but I'm not certain of the syntax. Using 'Vendor/Module' as an example.

My Layout File:

/html/public/app/code/Vendor/Module/view/frontend/layout/customer_account_edit.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
    <body>
        <referenceContainer name="customer_account">
            <block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Vendor_Module::customer/form/edit.phtml" cacheable="false"></block>
        </referenceContainer>
    </body>
</page>

Does anyone know if I'm using the correct reference container or if that's even the issue I'm facing?

1
  • The only way I have been able to get Magneto to load my template is to either remove the core layout file [/vendor/magento/module-customer-custom-attributes/view/frontend/layout/customer_account_edit.xml] so that it loads my layout file [/app/code/MyVendor/MyComponent/view/frontend/layout/customer_account_edit.xml] or change the template directly in the core layout file. Basically I am unable to get my layout file to load.
    – user857276
    Aug 2, 2019 at 20:46

1 Answer 1

1

Something like this should work

https://github.com/DominicWatts/EmailCC/blob/master/view/frontend/layout/customer_account_edit.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">
    <update handle="customer_account"/>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Xigen_CC::form/edit.phtml" cacheable="false">
                <container name="form.additional.info" as="form_additional_info"/>
                <block class="Magento\Customer\Block\Form\Edit" name="email_cc" template="Xigen_CC::form/email_cc.phtml"/>
            </block>
        </referenceContainer>
    </body>
</page>

https://github.com/DominicWatts/EmailCC/blob/eb29ce70042d2fdc755a855c7e7b181a671a3367/view/frontend/templates/form/edit.phtml#L80

 <?=$block->getChildHtml('email_cc')?>

https://github.com/DominicWatts/EmailCC/blob/master/view/frontend/templates/form/email_cc.phtml

<?php
$emailCc = $block->getCustomer()->getCustomAttribute('email_cc');
$customerEmailCC = $emailCc ? $emailCc->getValue() : null;
?>
<fieldset class="fieldset create account" >
    <legend class="legend">
        <span><?=$block->escapeHtmlAttr(__('Email Copy To'))?></span>
    </legend>
    <br>
    <div class="field email_cc">
        <label for="email_cc" class="label"><span><?=$block->escapeHtmlAttr(__('Email Address (Comma separated)'));?></span></label>
        <div class="control">
            <input id="email_cc" class="input-text" name="email_cc" value="<?=$block->escapeHtmlAttr($customerEmailCC);?>" title="<?=$block->escapeHtmlAttr(__('Email Copy To'));?>" type="text" autocomplete="off" />
        </div>
    </div>
</fieldset>
1
  • The only way I have been able to get Magneto to load my template is to either remove the core layout file [/vendor/magento/module-customer-custom-attributes/view/frontend/layout/customer_account_edit.xml] so that it loads my layout file [/app/code/MyVendor/MyComponent/view/frontend/layout/customer_account_edit.xml] or change the template directly in the core layout file. B
    – user857276
    Aug 2, 2019 at 19:27

Your Answer

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

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