Magento 2.1.3: Overriding of vendor layout file with my custom layout file in Magento 2.1.3 is not working?

magento.stackexchange https://magento.stackexchange.com/questions/228766

Question

I have created a custom module in Magento 2.1.3 and its layout file is located in

app/code/RP/Testmodule/view/frontend/layout/customer_account_create.xml

but the system loads the layout from

vendor/magento/module-customer/view/frontend/layout/customer_account_create.xml

instead of my custom layout file.

How can I override this vendor layout file with my custom layout file?

My customer_account_create.xml file is

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_form_register">
        <arguments>
            <argument name="template" xsi:type="string">RP_Testmodule::form/register.phtml</argument>
        </arguments>
    </referenceBlock>
    </body>
</page>

but the module does not take this layout.

I have created the resister.phtml and it is located in

app/code/RP/Testmodule/view/frontend/templates/form/register.phtml

My register.phtml file is

<h1>Test</h1>

My module.xml file is

app/code/RP/Testmodule/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="RP_Testmodule" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Customer" />
        </sequence>
    </module>
</config>

My di.xml file is

app/code/RP/Testmodule/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
</config>

My registration.php file is

app/code/RP/Testmodule/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'RP_Testmodule',
    __DIR__
);

These commands are executed successfully

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy

php bin/magento cache:clean

php bin/magento cache:flush

But all after that, still it's not working.

Thanks in advance

Was it helpful?

Solution

Try this:

    <referenceBlock name="customer_form_register">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">RP_Testmodule::form/register.phtml</argument>
        </action>
    </referenceBlock>

This is working for me.

OTHER TIPS

Change to your template with:

<referenceBlock name="customer_form_register" template="Vendor_Modulename::filename.phtml"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top