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.

Marius
199k55 gold badges431 silver badges837 bronze badges
asked Nov 20, 2015 at 15:15

1 Answer 1

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}.

answered Nov 20, 2015 at 15:17
3
  • 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. Commented Nov 20, 2015 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} Commented Nov 20, 2015 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. Commented Nov 20, 2015 at 15:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.