如何在Opencart中动态添加JavaScript?

use*_*030 0 javascript php jquery opencart

我想在category.tpl中使用jQuery插件.将文件放在javascript/jquery目录中.现在,如何使用这个插件?

Mar*_*ler 7

/* one can load JS like that: */    
if(file_exists('catalog/view/javascript/'.$this->config->get('config_template').'/script.js')) {
    $this->document->addScript('catalog/view/javascript/'.$this->config->get('config_template').'/script.js');
}
Run Code Online (Sandbox Code Playgroud)

使用现有函数是"正确的方法",而不是手动将脚本添加到header.tpl中.

作为提示,基于下面的答案 - 可以循环一个文件名数组,以便控制加载顺序,这通常与它们可能相互依赖时相关.