2

I am trying to inject a javascript file in specific page in my admin form. Currently I am overriding a community extension and so far the backend part of the code works as expected. But so far my attempts to load the script were unsuccessful.

An answer in different post states that there is a specific order when creating the appropriate xml node, a quote from there:

To load it on just admin dashboard use the (full 3 element) route with underscores as separators to the page

So, I've dumped the following values in my page:

Mage::app()->getRequest()->getControllerName(); // -> adminhtml_sport
Mage::app()->getRequest()->getActionName(); // -> edit
Mage::app()->getRequest()->getRouteName(); // -> sport
Mage::app()->getRequest()->getModuleName(); // -> sport

What I've added in my xml file:

<adminhtml_sport_sport_edit>
    <reference name="head">
        <action method="addJs"><script>path/custom/script.js</script></action>         
    </reference>
</adminhtml_sport_sport_edit>

did not work. As a last note, I would like to ask: Can this be achieved by using the config.xml file in my custom extension and nowhere else?. Thank you for your time.

2

Try with the layout handle sport_adminhtml_sport_edit instead of adminhtml_sport_sport_edit.

The rule for determining the layout handle is {module}_{controller}_{action}.

  • Given that I've placed this code in app/code/local/myvendor/myext/etc/config.xml are there any parent nodes for sport_adminhtml_sport_edit? Currently I tried with <adminhtml><layout> and then my node. – user33388 Nov 20 '15 at 15:21
  • you should add this inside one of your modules layout file not in config.xml. something like app/design/adminhtml/default/default/layout/{layout_file.xml} – Marius Nov 20 '15 at 15:38
  • So as it seems, I really can't do it without creating the xml file in /layout/. I also added the <updates> node and it's childs pointing to my newly created file, and all seems to be working fine. Really appreciated, thank you. – user33388 Nov 20 '15 at 15:48

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.