dpwtr666638 2016-11-02 04:34
浏览 140
已采纳

使用Prestashop模块将Javascript代码添加到特定页面

I'm developing a custom Prestashop Module. The requirement is simple: Add a predefined block of javascript code to specific sections of the shopping process. Those are:

  • Home page
  • Product page
  • Product added to cart
  • Purchase completed

The code will be specific to each page.

I already read the basics of module development, but I can't find documentation for this specific functionality.

I already have a working module that is installable and configurable from the back office admin. I'm assuming I need to extend the footer and check the page currently being served, but I have no idea how to do this.

  • 写回答

3条回答 默认 最新

  • duanluan3651 2016-11-02 09:23
    关注

    It's more simple than it appears :), you have to check in which page you are, in your hookDisplayHeader method add some if:

    public function hookDisplayHeader($params){
        /* some code */
    
        // check if we are in homepage
        if($this->context->controller->php_self == 'index'){
            $this->context->controller->addJS('path-to-index-js');
        }
    
        // check if we are in product page
        if($this->context->controller->php_self == 'product'){
            $this->context->controller->addJS('path-to-product-js');
        }
    
        // and so on for all other pages
        /* ... */
    
        /* some code */
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 java根据模板,生成word文档,需要带目录
  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做
  • ¥15 通关usb3.0.push文件,导致usb频繁断连
  • ¥15 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造