Prestashop 1.6 addJS和andCss不能在功能模块getContent()中为admin

问题描述:

我会将样式和JavaScript代码添加到新模块的页面'configure'中。在功能上的getContent()我使用:Prestashop 1.6 addJS和andCss不能在功能模块getContent()中为admin

\t \t public function getContent($param){ 
 
\t \t \t $output = null; 
 

 
\t \t \t $this->context->controller->addCSS(($this->_path).'style_module.css', 'all'); 
 
\t \t 
 
\t \t \t return $output.$this->displayForm(); 
 
\t \t }

的URL样式或JavaScript代码管理页面无法显示。

如何在功能getContent()中添加样式或js在admin中配置模块?

添加这个文件你需要使用一个钩子,在这种情况下,如果你使用1.6版本,是“actionAdminControllerSetMedia”。

首先你需要说的是,在这个钩子模块的安装方法注册此模块:

$this->registerHook('actionAdminControllerSetMedia'); 

的你需要指定什么必须做这个模块在这个钩子,所以你可以使用在钩功能的addCSS或addJS功能,如下所示:

public function hookActionAdminControllerSetMedia($params) { 
$this->context->controller->addJS($this->_path.'views/js/hs_custom.js'); 

}

Source.

希望它可以帮助你。

+0

此解决方案不起作用。脚本hs_custom.js不会显示在源代码管理页面的配置选项卡我的模块。有人知道为什么不行吗? – Arasowsky

+0

嗨,检查你的代码,它对我来说工作得很好。确保文件的路径正确,并且文件存在。 – Addis

+0

它启动时,我使用Context :: getContext-> controller-> addJS()。 现在我使用$ this-> context-> controller-> addJS,它也可以工作。 我不明白Prestashop :) – Arasowsky