1

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

3 Answers 3

2

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

2

There are two way the override the template in the custom module....

First :

<?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">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Kh_Registration::form/register.phtml</argument>
        </action>
    </referenceBlock>
</body>
</page>

Second :

<?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>

The way I posted in the question/below is not working because, according to issue #3356 on the Magento 2 GitHub repo, there are a number of cases where the method won’t work.

<?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.phtml</argument>
        </arguments>
    </referenceBlock>
</body>
</page>
1
  • Is this working now
    – Jaisa
    Feb 22, 2019 at 11:06
1

It should be .phtml not .php:

<argument name="template" xsi:type="string">Kh_Registration::form/register.phtml</argument>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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