简体   繁体   English

Prestashop-如何添加内联脚本?

[英]Prestashop - How to add inline script?

I would like to know how to add JS inline in the of my website by the PHP file of my module. 我想知道如何通过模块的PHP文件在网站的JS中内联添加JS。 I tried the method "addJS" from the main controler but it seems that this is only works for importing external JS file. 我尝试了来自主控制器的方法“ addJS”,但看来这仅适用于导入外部JS文件。

Do you know how I can do to add my script in the head from the "hookDisplayRightColumn" function ? 您知道如何通过“ hookDisplayRightColumn”函数将脚本添加到头部吗?

Thank you in advance for your help and have a nice day! 预先感谢您的帮助,祝您有美好的一天!

Mickaël 的Mickaël

Short answer: you can't. 简短的答案:您不能。 If you need to add something to header, then you need to call hookDisplayHeader . 如果需要在header中添加一些内容,则需要调用hookDisplayHeader

I assume that you want to add some variables for your script; 我假设您想为脚本添加一些变量; For that puropose I can suggest Media:addJsDef() and $this->context->controller->addJS() . 为此,我可以建议Media:addJsDef()$this->context->controller->addJS() Howeverm Media:addJsDef() is only avaiable on PrestaShop 1.6 or later; 然而, Media:addJsDef()仅在PrestaShop 1.6或更高版本上可用; If you need to define some JS variables in your page on PrestaShop 1.5 or lower, you indeed need to use hookDisplayHeader . 如果需要在PrestaShop 1.5或更低版本的页面中定义一些JS变量,则确实需要使用hookDisplayHeader

EDIT: You may also try to insert your script using hookDisplayRightColumn and then write a block of script to header (not sure if that would work though, also very bad practice). 编辑:您也可以尝试使用hookDisplayRightColumn插入脚本,然后将脚本块写入标头(不确定是否可以使用,这也是非常不好的做法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM