使用 Prestashop 模块将 Javascript 代码添加到特定页面 [英] Adding Javascript code to specific pages using Prestashop Module

查看:49
本文介绍了使用 Prestashop 模块将 Javascript 代码添加到特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自定义 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:

  • 主页
  • 产品页面
  • 产品已加入购物车
  • 购买完成

代码将特定于每个页面.

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.

推荐答案

它比看起来更简单:),你必须检查你在哪个页面,在你的 hookDisplayHeader 方法中添加一些 <代码>如果:

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 */
}

这篇关于使用 Prestashop 模块将 Javascript 代码添加到特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆