php将页数显示在页脚,php – 在prestashop的页脚显示我的模块JS

我正在prestashop开发一个模块.我的模块配置页面有一个JS.我正在使用displayBackOfficeHeader钩子在头文件中添加我的JS.但是在配置我的模块后安装我的模块后,它给了我Jquery问题,因为我的JS在jquery.js之前添加了顶部意味着

Que 1)如何管理我的JS应该在Jquery.js之后添加标题?

Que 2)如果我们不能像que Ist一样管理那么如何在页脚中添加JS?

解决方法:

在大多数情况下,要将任何资产(JavaScript或CSS)添加到后台(管理页面),您应该使用钩子actionAdminControllerSetMedia().

正确注册JavaScript文件的完整步骤如下:

步骤1.在模块安装上注册挂钩:

public function install()

{

if (!parent::install()) {

return false;

}

// After a module installation, register the hook

if (!$this->registerHook('actionAdminControllerSetMedia')) {

return false;

}

return true;

}

第2步.然后,添加您的JavaScript资源:

public function hookActionAdminControllerSetMedia()

{

// Adds jQuery and some it's dependencies for PrestaShop

$this->context->controller->addJquery();

// Adds your's JavaScript from a module's directory

$this->context->controller->addJS($this->_path . 'views/js/example.js');

}

可以使用不同的方法和几种方法在后台(管理页面)中注册资产(它们按执行顺序列出):

>钩子hookDisplayBackOfficeHeader()

>控制器的方法AdminControllerCore :: setMedia()

>钩子actionAdminControllerSetMedia()

>模块的方法Module :: getContent()

>钩子hookDisplayBackOfficeFooter()

要添加内联代码,最好的方法是使用hook hookDisplayBackOfficeFooter().例如:

public function hookDisplayBackOfficeFooter()

{

return '

var EXAMPLE_VARIABLE = "Hello, Zapalm!";

';

}

注意:在PrestaShop 1.7中,如果有人想要从外部资源添加JavaScript,例如,从https://ajax.googleapis.com,新方法$this-> context-> controller-> registerJavascript()使用选项’server’=>应该使用’remote’.例如:

$this->context->controller->registerJavascript(

'three.js',

'https://ajax.googleapis.com/ajax/libs/threejs/r84/three.min.js',

['position' => 'bottom', 'priority' => 100, 'server' => 'remote']

);

标签:prestashop,prestashop-1-6,php

来源: https://codeday.me/bug/20190927/1824962.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值