You always get people saying never to modify the core magento files (/app/code/core/), but what about the /js/mage/ files? Will this get overwritten when you upgrade magento? Is there an alternative place to create them (e.g. with core in /app/code/local/mage/)?
2 Answers
Never edit any file that is in the core.
This includes php classes, template classes, and js files.
What you can do is to "somehow" rewrite them.
You can clone any file in a custom folder but still in js
folder.
For example js/my_company/
.
Then you can edit the layout files of you theme and make them include your file instead of the original one.
<reference name="head">
<action method="removeItem"><type>js</type><name>original/js/file</name></action>
<action method="addJs"><name>my_company/filename.js</name></action>
<reference>
If you want to extend a js "class" don not clone the full file.
You can create your own and just add it to the page.
See a very nice explanation from @Fooman on how to manage these kind of js extensions.
-
Hey Marius, thanks for the answer, my confusion comes from the following - the /js/mage folder isn't actually in the 'core' folder (/app/code/core/), so do they still count as core files? This is what I'm trying to do.– eddhallCommented Feb 3, 2014 at 12:08
-
1@Edward. It depends what
core
means to you. For me it means every file that comes with the Magento archive. The templates are also not located inapp/code/code
but you should not edit any file inapp/design/frontend/base/default
either. Same goes for any file in thejs
folder.– Marius ♦Commented Feb 3, 2014 at 12:15 -
Hey Marius, Good to know thanks. All I'm trying to do is add one line of text to a js file, would the fooman link be the best way of doing this?– eddhallCommented Feb 10, 2014 at 15:44
js/mage
is a part of the core Magento Javascript library. In Magento there are a few ways where a Javascript file should live. Your custom JS code can live under a skin JS directory eg. skin/frontend/default/foobar/js
or your own custom library under js/foobar
. This is probably the better way to override the Javascript file you're trying to edit. If you edit the js/mage
folder contents yes, it will get overwritten in an upgrade unless you specifically exclude that directory/files - but after that could come the real trouble.