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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵