0

我想在头部添加一个脚本,但是使用事件我找不到它是如何工作的。

我安装了一个添加了一个脚本的事件,但它显示在 HTML 标记之前。但我想在头标签内显示。

扩展/模块/shop.php

class ControllerExtensionModuleShop extends Controller {
    public function index() {
      //$this->document->addStyle('catalog/view/javascript/css/test.css');
      //$this->document->addScript('catalog/view/javascript/js/test.js');
      echo "<script src="catalog/view/javascript/js/test.js" type="text/javascript"></script>";
    }
}

行政

class ControllerExtensionModuleShop extends Controller {
public function install() {
        $this->model_setting_event->addEvent('shop', 'catalog/view/common/header/before', 'extension/module/shop/index');
    }

    public function uninstall() {
        $this->model_setting_event->deleteEventByCode('shop');
    }
4

1 回答 1

1

使用此触发器添加您的事件:

$this->model_setting_event->addEvent('shop', 'catalog/controller/common/header/before', 'extension/module/shop/index');

shop.php应该是:

<?php
class ControllerExtensionModuleShop extends Controller {
    public function index(&$route = '', &$data = array(), &$output = '') {
        $this->document->addScript('catalog/view/javascript/js/test.js');
    }
}
于 2018-09-03T02:03:13.250 回答