0

I am trying to inject template code in default customer account login page.

I have created a template file under

vendor_name/module_name/view/frontend/templates/custom_template.phtml

How can I inject it in default customer login page ? I tried to inject it by creating a layout file under vendor_name/module_name/view/frontend/layout/ directory but after clearing cache and checking storefront, it does not seem to be working.

Can anyone provide suggestion on how to accomplish it ?

2 Answers 2

1

Create a layout file vendor_name/module_name/view/frontend/layout/customer_account_login.xml

replace template

   <?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="custom_template" xsi:type="string">vendor_name_module_name::custom_template.phtml</argument>
               </action>
           </referenceBlock>
       </body>
   </page>

add new content using container customer.login.container

   <?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>
           <referenceContainer name="customer.login.container">
               <block class="Magento\Framework\View\Element\Template" after="customer.new" name="custom.template" template="vendor_name_module_name::custom_template.phtml"/>
           </referenceContainer>
       </body>
   </page>

add new content using container form.additional.info

   <?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>
           <referenceContainer name="form.additional.info">
               <block class="Magento\Framework\View\Element\Template" name="custom.template" template="vendor_name_module_name::custom_template.phtml"/>
           </referenceContainer>
       </body>
   </page>

add new content using container content

   <?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>
           <referenceContainer name="content">
               <block class="Magento\Framework\View\Element\Template" name="custom.template" after="customer.login.container" template="vendor_name_module_name::custom_template.phtml"/>
           </referenceContainer>
       </body>
   </page>
2
  • Thanks for the help.Yes, it works but it replaces the default login page, I am trying to add custom code just below the "Create an account" button. Instead of setTemplate, is there any method available which lets add a code to existing templates. Aug 4, 2016 at 6:22
  • Don't mention it. I added some solutions.
    – Vitalii
    Aug 4, 2016 at 21:18
0

Create the file module_directory/view/frontend/layout/customer_account_login.xml in your module with this contents:

<?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>
        <referenceContainer name="customer.login.container">
            <block class="Magento\Framework\View\Element\Template" template="Your_Module::custom_template.phtml" name="custom.template" after="customer.new"/>
        </referenceContainer>
    </body>
</page>

You should aslo add Magento_Customer to your module.xml sequence element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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