Ashfame
Ashfame

Reputation: 1759

How to load a js file on magento admin dashboard

I am trying to load a js file through XML on the dashboard page of magento admin, but am unable to get it right.

Here is the part of code that I have added in my config file:

<config>
    <adminhtml>
        <layout>
            <updates>
                <anattadesign_abandonedcarts>
                    <file>my_extension.xml</file>
                </anattadesign_abandonedcarts>
            </updates>
        </layout>
    </adminhtml>
</config>

And my contents of my_extension.xml which is placed under /app/design/adminhtml/default/default/layout/ is:

<layout>
    <default>
        <reference name="head">
            <action method="addJs"><script>my_extension/adminhack.js</script></action>
            <action method="addJs"><script>prototype/prototype.js</script></action>         
        </reference>
    </default>
</layout>

I understand that I am trying to load a js file for the whole admin this way, but I would like to know both, loading on a certain page, and how to find out the name if I want to load it on a certain page and if default is the correct one to make it load on all admin pages.

Upvotes: 7

Views: 12705

Answers (1)

Lucas Moeskops
Lucas Moeskops

Reputation: 5443

Using default should load it on all pages, indeed.

To load it on just admin dashboard use the (full 3 element) route with underscores as separators to the page. For the dashboard this is Adminhtml/(controllers)/Dashboard(Controller)/index(Action).

<layout>
  <adminhtml_dashboard_index>
    <reference name="head">
            <action method="addJs"><script>my_extension/adminhack.js</script></action>
            <action method="addJs"><script>prototype/prototype.js</script></action>         
        </reference>
  </adminhtml_dashboard_index>
</layout>

N.B. I have not tested this code, but I think it should do it.

Upvotes: 7

Related Questions