Magento – Magento 2.3 customer form register template file override

magento2template-override

I am working on Magento 2.3 version. I have create custom module for the override the register.phtml file but it is not working. I have provided some files details

Kh/Registration/etc/module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Kh_Registration" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Customer"/>
        </sequence>
    </module>
</config>

Kh/Registration/view/frontend/layout/customer_account_create.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">
<body>
    <referenceBlock name="customer_form_register">
        <arguments>
            <argument name="template" xsi:type="string">Kh_Registration::form/register.php</argument>
        </arguments>
    </referenceBlock>
</body>
</page>

Kh/Registration/view/frontend/templates/form/register.php

<h1>New registration file </h2>

I have enable module, clear cache but it shows core magento file

vendor/magento/module-customer/view/frontend/templates/form/register.phtml

Please advice me

Best Answer

If you using magento 2.2.X and greater then

then you can use

<?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_form_register"  template="Kh_Registration::form/register.phtml"/>
</body>
</page>

Also, you have to ensure Magento_Customer load fast then Kh_Registration is loading, So please check Config.php at app/etc/ .if not then you need to need to run setup upgrade command and it will update module sequence as you have added <sequence> at module.xml.

Also,as Kishor Hase said, you template file extension should be .phtml NOT .php

Related Topic