6

I had developed "Hello world" extension in Magento 2.

I want to override Customer login form of core files. What is correct way for overriding Customer login form file in Magento 2.

I have coded like this

<referenceBlock name="customer_form_login">
    <action method="setTemplate">
     <argument name="template"xsi:type="string">Namespace_Loginoverride::login.phtml</argument>
   </action>
</referenceBlock>

but above code does not work for me

Please help me. Any help would be appreciated.

4 Answers 4

6

A few things:

  • First, here's a link in the docs to set block template.
  • Next, the documentation states that the <action> node is deprecated.
  • Also, I found that I was able to accomplish the task you have asked about by following this page in the docs.

To successfully replace the Magento_Customer::form/login.phml template with a custom template:

  1. Create the following directory structure app/design/frontend/<Vendor>/<theme>/Magento_Customer/templates/form/
  2. Add the template file app/design/frontend/<Vendor>/<theme>/Magento_Customer/templates/form/login.phtml
  3. Add desired custom code within the login.phtml file.
  4. Verify the custom theme is already in place (or enable it if you haven't already) by going to: Admin panel->Content->Design Configuration->Your Store or Store View. And sure your custom theme shows under Applied Theme
  5. If you're not in developer mode, or if you are in developer mode and have manually deployed static content (php bin/magento setup:static-content:deploy) then you'll want to clear your cache and pub/static/ (except the .htaccess) directories. If you are in developer mode and haven't manually deployed static assets skip this step.
  6. Refresh your http://<YOUR_DOMAIN.COM>/customer/account/login/ page, or go visit it, and view the desired changes.
1

You have to just add below code inside layout file,

<referenceBlock name="customer_form_login">
    <action method="setTemplate">
     <argument name="template" xsi:type="string">Namespace_Loginoverride::login.phtml</argument>
   </action>
</referenceBlock>

You must add to your login.phtml file inside below location app/code/Namespace/LoginOverride/view/frontend/templates/login.phtml

1
  • Thank you fro answer Rakesh, unfortunately it's not work for me , i have already done it. May 21, 2016 at 7:25
1

All you need is the following steps Not sure if you are still looking for the answer: Step one is in your module create -> view/frontend/templates/layout/customer_account_login.xml

You are only focusing on the login page so do the following

enter image description here

and view/frontend/templates/form/login.phtml

add what you change is

example: add the h1 tag and test it out

enter image description here

0

You're missing a space in your code:

Instead of:

<argument name="template"xsi:type="string">Namespace_Loginoverride::login.phtml</argument>

It should be:

<argument name="template" xsi:type="string">Namespace_Loginoverride::login.phtml</argument>

Also ensure that app/code/Namespace/Loginoverride/view/frontend/templates/login.phtml is the right path of your template.

5

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.