Prestashop 1.7.x注册Javascript 1.7 inline

时间:2017-08-08 10:59:02

标签: javascript prestashop prestashop-1.7

我想使用registerJavascript()在模块中注册Javascript文件。与inline => false一起使用时,一切正常。但是我希望它被内联,所以我使用inline => true并且调试工具抛出错误:

内联.js文件是否处理不同?我的错误是什么?

Warning: file_get_contents(/modules/xxx/js/cookieconsent.inline.js): failed to open stream: No such file or directory

mymodule.php中的函数本身

public function hookActionFrontControllerSetMedia( $params ) {

...

$this->context->controller->registerJavascript(
        'cookieconsentinline',
        'modules/' . $this->name . '/js/cookieconsent.inline.js', [
            'position' => 'bottom',
            'inline' => true,
            'priority' => 100,
        ]
    );

...

}

它也不适用于_PS_MODULE_DIR_$this->dir either

1 个答案:

答案 0 :(得分:0)

您的解决方案对我也不起作用。但是你可以通过header hook注册javascript。这是ps_shoppingcart模块中的其他内容。

...

        public function hookHeader()
    {
        if (Configuration::isCatalogMode()) {
            return;
        }

        if (Configuration::get('PS_BLOCK_CART_AJAX')) {
            $this->context->controller->registerJavascript('modules-shoppingcart', 'modules/'.$this->name.'/ps_shoppingcart.js', ['position' => 'bottom', 'priority' => 150]);
        }
    }
    ....
    public function install()
    {
        return
            parent::install()
                && $this->registerHook('header')
                && $this->registerHook('displayTop')
                && Configuration::updateValue('PS_BLOCK_CART_AJAX', 1)
        ;
    }