4

I'm trying to override customer's login.phtml file and I am able to manage the override by creating custom theme Tracks/customtheme, also I put the .phtml file in my custom theme like this /app/design/frontend/Tracks/customtheme/Magento_Customer/templates/form/login.phtml and it is working properly.

My question is, there is a blank folder named Magento in /app/design/ directory after downloading M2. So, why we can't override .phtml file like this /app/design/frontend/Magento/luma/Magento_Customer/templates/form/login.phtml? Any suggestion should be appreciated. Thanks in advance.

2

For override login.phtml file at module level you need to create customer_account_login.xml file to override and using setTemplate method we need to set our customm module file path.

Check link, How to override Customer login.phtml file

<action method="setTemplate">
            <argument name="template" xsi:type="string">Rbj_Customer::form/login.phtml</argument>
</action>
  • Thanks for suggestion. But if i want to override phtml file not as module level then creating custom theme is compulsory in M2? For ex if i want to override luma theme's login.phtml file then it's not working if i put that file in Magento namespace like following directory. Am i right? /app/design/frontend/Magento/luma/Magento_Customer/templates/form/login.phtml – Raj Aug 11 '18 at 4:46
  • Hi Raj, If you want to override file in theme level, you must create new theme. if you want to change directly in luma theme you need to changes directly inside vendor/magento/theme-frontend-luma/Magento_Customer/templates – Rakesh Jesadiya Aug 11 '18 at 5:01
0

You can create the .phtml file in Magento directory under app/design/frontend directory. However, you have to associate the same .phtml file in Magento/CustomTheme module configuration. Still, it is not recommended to use the default Magento namespace for the custom theme, as it is out of the Magento conventions. So, you should create your own namespace.

Which you did already.

0

Method 1: You can use the below code:

<?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_login">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Vendor_Module::customer/login.phtml</argument>
        </action>
    </referenceBlock>
</body>
</page>

Method 2: As action is depreciated you can use the below code:

<?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_login" template="Vendor_Module::customer/login.phtml"/>
    </body>
</page>

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.