1

I am trying to load a custom JS script on the Magento admin panel login page (Magento version 1.7.0.2).

As per the accepted answer in Issue adding javascript to magento admin page, I added the following lines to app/design/adminhtml/default/default/layout/local.xml:

<adminhtml_index_login>
  <reference name="head">
    <action method="addJs"><script>dev/test.js</script></action>
  </reference>
</adminhtml_index_login>

Note: the above code was added inside the existing <layout></layout> tags.

I cleared the cache but it does not add the dev/test.js file to the HTML header.

What is wrong with my code and/or implementation method?

Update 2018-03-06:

Tried the following in app/design/adminhtml/default/default/layout/main.xml but the result is the same (file not added to login page):

<?xml version="1.0"?>
<layout>
  ...
  <adminhtml_index_login>
    <reference name="head">
      <action method="addJs"><script>test.js</script></action>
    </reference>
    <block type="core/text_list" name="root" output="toHtml">
      <block type="adminhtml/template" name="content" template="login.phtml">
        <block type="core/text_list" name="form.additional.info" />
      </block>
    </block>
  </adminhtml_index_login>
  ...
</layout>
1

Try placing it inside app/design/adminhtml/default/default/layout/main.xml file, where you can find adminhtml_index_login layout update

UPDATE

My mistake... if you check app/design/adminhtml/default/default/template/login.phtml you will see all head resources are loaded there, because of that the call through layout files don't do anything, as head block is not called / used

So, you'd add your js directly in that template

  • The result is still the same - the JS file isn't added to the login page. I cleared the cache after making the change also. – Chris Mar 5 '18 at 19:38
  • Are u using custom theme for adminhtml? – Raul Sanchez Mar 5 '18 at 19:50
  • No custom theme for adminhtml, only a custom theme for the frontend. – Chris Mar 5 '18 at 23:08
  • Update your question witth the code changes you've tried in layout/main.xml file – Raul Sanchez Mar 6 '18 at 12:24
  • Added main.xml code to question as requested – Chris Mar 6 '18 at 17:06

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.