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>
asked Nov 19, 2015 at 5:16
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 Commented 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>
answered Nov 19, 2015 at 5:20
17
  • He don't want to duplicate the file. Commented 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 Commented Nov 19, 2015 at 5:24
  • @AbdulGhaffar added comment Commented Nov 19, 2015 at 5:26
  • @AbdulGhaffar updated the answer.. Commented Nov 19, 2015 at 5:27
  • @QaisarSatti " js/yourfolder/v1.js" you mean js in main project Commented 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>
answered Nov 19, 2015 at 6:03
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>
answered Nov 19, 2015 at 5:37
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 Commented Nov 19, 2015 at 5:47
  • This will add js from js folder only and not from skin_js Commented Nov 19, 2015 at 5:48
  • have you used one form in frontend & second in backend right? Commented Nov 19, 2015 at 5:48
  • in magento js/prototype/prototype.js is use forntend and also backend Commented 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 Commented Nov 19, 2015 at 5:56

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.