Shopware 5.2.11 在我的插件中包含 JavaScript
Shopware 5.2.11 include JavaScript in my plugin
我想在我的插件中添加一个 JavaScript 文件。我正在关注这个 tutorial 并且能够在我的安装中成功获得当天的口号(流浪汉)。
另外我想加载一个 JavaScript 文件。我更改了 index.tpl 并添加了以下行:
{* Include own Javascript Code *}
{block name="frontend_index_header_javascript_jquery_lib"}
{debug}
{$smarty.block.parent}
{if $myVariable}<script type="text/javascript" src="{link file='frontend/_public/src/js/myFile.js'}"></script>{/if}
{/block}
查看生成的源代码html脚本标签加载成功。但是,我的 JavaScript 文件根本不会被加载。我必须将文件放在我的插件文件夹中的什么位置?
目前我有这个结构
NameOfZipfile.zip
└──Frontend
├─MyPlugin
│ └─Views
│ ├─_public
│ │ └─src
│ │ └─js
│ │ └─myFile.js
│ └─frontend
│ └─index
│ └─index.tpl
└─Bootstrap.php
我正在使用 shopware 5.2.11。我不想添加内联脚本。我做错了什么?
(代表OP发帖).
解决方案,我在 Bootstrap.php 安装方法中添加了以下内容:
$this->subscribeEvent('Theme_Compiler_Collect_Plugin_Javascript', 'addJsFiles');
还有这个函数:
public function addJsFiles(Enlight_Event_EventArgs $args){
$jsFiles = array(__DIR__ . '/Views/_public/src/js/myFile.js');
return new Doctrine\Common\Collections\ArrayCollection($jsFiles);
}
如果使用 grunt,您将使用此命令将所有插件的 js 文件添加到您的 /web/cache/config_' + shopId + '.json' 文件中:
bin/consolesw:theme:dump:configuration
我想在我的插件中添加一个 JavaScript 文件。我正在关注这个 tutorial 并且能够在我的安装中成功获得当天的口号(流浪汉)。
另外我想加载一个 JavaScript 文件。我更改了 index.tpl 并添加了以下行:
{* Include own Javascript Code *}
{block name="frontend_index_header_javascript_jquery_lib"}
{debug}
{$smarty.block.parent}
{if $myVariable}<script type="text/javascript" src="{link file='frontend/_public/src/js/myFile.js'}"></script>{/if}
{/block}
查看生成的源代码html脚本标签加载成功。但是,我的 JavaScript 文件根本不会被加载。我必须将文件放在我的插件文件夹中的什么位置?
目前我有这个结构
NameOfZipfile.zip
└──Frontend
├─MyPlugin
│ └─Views
│ ├─_public
│ │ └─src
│ │ └─js
│ │ └─myFile.js
│ └─frontend
│ └─index
│ └─index.tpl
└─Bootstrap.php
我正在使用 shopware 5.2.11。我不想添加内联脚本。我做错了什么?
(代表OP发帖).
解决方案,我在 Bootstrap.php 安装方法中添加了以下内容:
$this->subscribeEvent('Theme_Compiler_Collect_Plugin_Javascript', 'addJsFiles');
还有这个函数:
public function addJsFiles(Enlight_Event_EventArgs $args){
$jsFiles = array(__DIR__ . '/Views/_public/src/js/myFile.js');
return new Doctrine\Common\Collections\ArrayCollection($jsFiles);
}
如果使用 grunt,您将使用此命令将所有插件的 js 文件添加到您的 /web/cache/config_' + shopId + '.json' 文件中: bin/consolesw:theme:dump:configuration