Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include Javascript files into shopware5 theme

I am unable to add javascript files to my first Shopware5 theme. I tried the following method given in one of online articles. https://developers.shopware.com/designers-guide/theme-startup-guide/ I added my js files into the array on Theme.php file and upload javascript files to the ‘frontend/_public/src/js’

/** @var array Defines the files which should be compiled by the
javascript compressor */
protected $javascript = array(
'src/js/jquery.my-plugin.js'
);

However the above array was not avilable on my Theme.php file but I added my js files into the array and tried loading it on my theme. I cleared all my caches when I checked the site.

like image 267
Chathuraka Avatar asked Jan 28 '26 10:01

Chathuraka


1 Answers

You have to clear all caches and also do a re-compile of the theme. Have in mind that you have to place the js into frontend/_public.

The full path of your js-files should be themes/YourTheme/frontend/_public/src/js/jquery.my-plugin.js.

like image 55
Roman Avatar answered Jan 31 '26 00:01

Roman