How To Add Custom Javascript With My Changes Addon

A custom theme could impact it if it does not support the hooks for 'scripts'. However, I would expect that if that were the case that you'd have all sorts of problems.

Verify that you in fact have a js/addons/my_changes/your_script_name.js file in place.

Add the following line to your file:

and add this to your js/addons/my_changes/your_script_name.js file:

Clear your cache by manually removing/moving var/cache.

Clear your browser cache too.

Then open the browser inspector for your site by right-clicking and selecting "inspect".

You should see the messages in the console area related to the files that have loaded.

If not then either my_changes is not active or you have a typo in the pathname to the file.

I'm assuming this is the scripts.tpl in the design/themes/[my theme]/templates/common folder? If so, my js files are not linked in there.

Would it affect it if I'm using a third party purchased theme?

No, check source code for similar file

Thanks tbirnseth & eCom. I figured out the issue. The first issue I had was that it wasn't showing up in my source code of the page so I thought it wasn't getting included, but then I looked for that compiled "script-[random number].js" file that you mentioned eCom, and it was all in there.

And the reason it wasn't working, is because there seemed to have a conflict with some of the other javascript code. It's all fixed and it works fine now.

Thanks guys!

Do not use the var/theme_repository/basic/templates/addons/NAME ?

I asked in a separate thread about this.. The var directory seems redundant

The var/themes_repository area is for INSTALLATION of an addon. For instance, any theme based on the 'responsive' theme will have templates loaded from var/themes/responsive.... Once an addon is installed, then any changes to the theme templates should be done in the design/themes/[YOUR THEME]/ directory structure. But if you uninstall and addon and reinstall it, the theme templates for the addon will be removed and then reloaded from the var/themes_repository/responsive area.

Themes NOT based on the responsive theme will not have addons automatically install templates that are distributed in the var/themes_repository/responsive directory structure. Manual copying will need to occur. Some themes do this automatically within the theme installation itself, but there is no standard on how that's to be done.

Also If you want to distribute your addon, installation package should contain store-front templates in var/theme_repository/THEME directory. If your module is used on your store only, there is no need to use this directory

That's exactly what I have concluded as well. The directory layout for addons is just awful. Too much trivia needed to keep it operating properly,.

That's exactly what I have concluded as well. The directory layout for addons is just awful. Too much trivia needed to keep it operating properly,.

We have long argued for a single root for addons (php, templates, JS, etc.)....

But once you get used to it, and have setup a build environment to pull it into a proper archive, it's not too bad.

But once an addon is installed, all template stuff is in /design and everything else is in a static location. It's really only the template area that are annoying.

1 Like