3

I have to use a frontend js file in backend.Currently file is at

/skin/frontend/default/test/js/v1.js

and if I want to use it in backend I have to move it to

/skin/adminhtml/default/default/js/v1.js

but I don't want to duplicate it. So where should I place it. And what should be path in

<action method="addItem">
           <type>skin_js</type>
           <name>path of js file/v1.js</name>
</action>
1
  • "and if I want to use it in backend I have to move it to /skin/adminhtml/default/default/js/v1.js" yes that the only correct way to do so.you can not use front js in admintml in layout file.if you want to add ,do add it in your template file by providing front end js path Nov 19, 2015 at 5:26

3 Answers 3

1

add your file in js/yourfolder/v1.js you can use same for both admin and frontend

<action method="addJs">
                <script>yourfolder/v1.js</script>
            </action>
17
  • He don't want to duplicate the file. Nov 19, 2015 at 5:24
  • I don't understand , what are you saying. I said I don't want to make an other copy of file. I want to use original file which is @/skin/frontend/default/test/js/v1.js Nov 19, 2015 at 5:24
  • @AbdulGhaffar added comment Nov 19, 2015 at 5:26
  • @AbdulGhaffar updated the answer.. Nov 19, 2015 at 5:27
  • @QaisarSatti " js/yourfolder/v1.js" you mean js in main project Nov 19, 2015 at 5:30
3

That's easy. Just follow below steps:

  1. Move v1.js in js directory as /js/v1.js
  2. Access this file from both frontend & backend using below command in your layout xml file

>

<action method="addItem"><type>js</type><name>v1.js</name></action>
1

Please try same as bellow code in your frontend & backend layout file

frontend layout file

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

backend layout file

<default>
      <reference name="head">
        <action method="addJs"><script>test/test.js</script></action>
    </reference>
</default>
5
  • How is it possible, you are trying to access same form two different places with same path, with out placing it on specific point Nov 19, 2015 at 5:47
  • This will add js from js folder only and not from skin_js Nov 19, 2015 at 5:48
  • have you used one form in frontend & second in backend right?
    – Abdul
    Nov 19, 2015 at 5:48
  • in magento js/prototype/prototype.js is use forntend and also backend
    – Abdul
    Nov 19, 2015 at 5:52
  • you are follow same as prototype.js (location at forntend app\design\frontend\base\default\layout\page.xml and backend app\design\adminhtml\default\default\layout\main.xml
    – Abdul
    Nov 19, 2015 at 5:56

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.