1

I try to override admin login template, using Layout Block Argument. Here is the files I created to do that:

in Vendor/Module/view/adminhtml/layout/admin_login.xml I tried:

<referenceBlock name="admin.login">
   <arguments>
     <argument name="template" xsi:type="string">vendor_module::admin/login.phtml</argument>
   </arguments>
</referenceBlock>

But nothing Happened, so I changed with:

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

And now in magento2/var/log/system.log I have:

main.CRITICAL: Invalid template file: 'vendor_module::admin/login.phtml' in module: 'Magento_Backend' block's name: 'admin.login'

I have created the template file login.phtml in Vendor/Module/view/adminhtml/templates/admin/

so I don't know what's I'm doing wrong. I'm very new to Magento 2, I took the time to read Dev Docs and many forums but I can't find the solution by myself, anyone could help me?

Thank you so much!

0

In fact the problem come from that I'm not able to find a block to extend corresponding to login.phtml (view/adminhtml/templates/admin/login.phtml), if I enable printing block and template in Magento admin, I can see that the block name I should extend is \Magento\Backend\Block\Template, so I try to extend this one but it's a "top level" class. What I try: I created a block:

namespace Vendor\Module\Block\Adminhtml\Backend\Admin;

class Login extends \Magento\Backend\Block\Template
{
}

Add this line to my di.xml

<preference for="Magento\Backend\Block\Template" type="Vendor\Module\Block\Adminhtml\Backend\Admin\Login"/>

And create my Layout Vendor/Module/view/adminhtml/layout

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-login" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>

     <referenceBlock name="admin.login">
          <block class="Rcdevs\Openotp\Block\Adminhtml\Backend\Admin\Login" name="admin_login" template="admin/login.phtml" />
      </referenceBlock>      

</body>

and my view/adminhtml/templates/admin/login.phtml with the content I'd like to change.

The admin.login block has been well replaced with my template, but now the problem is because it's not a "particular block" all the phtml using \Magento\Backend\Block\Template are necessarily impacted and showing this message in system.log:

main.CRITICAL: Invalid template file: 'admin/login_buttons.phtml' in module: 'Vendor_Module' block's name: 'adminhtml_auth_login_buttons'

What can I do extend admin/login.phtml (admin.login block) only without touching others blocks? Thank you very much..

0

Did you use Vendor_Module or vendor_module?

Module path in layout config is defined as Vendor_Module, not vendor_module. Notice the uppercase in bold text.

For example, your module path is Project\Distributor, you call the module as Project_Distributor in layout config.

To change admin login block template, method 1:

<referenceBlock name="admin.login" template="Vendor_Module::admin/login.phtml" />

Or method 2:

<referenceBlock name="admin.login">
    <arguments>
        <argument name="template" xsi:type="string">Vendor_Module::admin/login.phtml</argument>
    </arguments>
</referenceBlock>

The filename is adminhtml_auth_login.xml, not admin_login.xml. Source: Magento 2 DevDoc

Make sure that your block template file path is /path/to/app/code/Vendor/Module/view/adminhtml/templates/admin/login.phtml. Notice that view, adminhtml, and templates are in lowercase.

After modifying your xml, flush magento cache (cache:flush), then reload your web browser.

  • Hello, thank you for your answer - yes I did, I made a mistake when writing vendor_module. The problem is elsewhere... – JulienR Jan 31 '17 at 6:59
  • I have updated my answer, about the filename. Could you try it? – Rendy Eko Prastiyo Jan 31 '17 at 7:42
  • Thank you very much, I don't know what's I'm doing wrong, but method 1 gives: main.CRITICAL: Invalid template file: 'Rcdevs_Openotp::admin/login.phtml' in module: 'Magento_Backend' block's name: 'admin.login', and method 2 do nothing. I have the correct file path in lowercase... Are you sure this method works for this particular case? – JulienR Jan 31 '17 at 10:17
  • I FOUND MY MISTAKE!!! If you have a vendor and a module name like mine, VENdor and ModULE (in this case it's strange but it's my case...) you HAVE TO write VENdor_ModULE not Vendor_Module like explained in all doc and forums! Thank you so much. – JulienR Jan 31 '17 at 12:32
  • Yes, as I have warned you about the case sensitive... – Rendy Eko Prastiyo Feb 2 '17 at 2:29

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.