如何将 Javascript 个文件包含到 shopware5 主题中

How to include Javascript files into shopware5 theme

我无法将 javascript 个文件添加到我的第一个 Shopware5 主题中。我尝试了其中一篇在线文章中给出的以下方法。 https://developers.shopware.com/designers-guide/theme-startup-guide/ 我将我的 js 文件添加到 Theme.php 文件的数组中,并将 javascript 文件上传到“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'
);

但是上面的数组在我的 Theme.php 文件中不可用,但我将我的 js 文件添加到数组中并尝试将它加载到我的主题中。我检查站点时清除了所有缓存。

您必须清除所有缓存并重新编译主题。请记住,您必须将 js 放入 frontend/_public

你的 js 文件的完整路径应该是 themes/YourTheme/frontend/_public/src/js/jquery.my-plugin.js.